Skip to content

Commit f374a34

Browse files
authored
Move URL out of RequestInfo to match DOM types (#3121)
1 parent 506be97 commit f374a34

File tree

4 files changed

+70
-42
lines changed

4 files changed

+70
-42
lines changed

src/workerd/api/cache.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ class Cache: public jsg::Object {
7272
JSG_METHOD(keys);
7373

7474
JSG_TS_OVERRIDE({
75-
delete(request: RequestInfo, options?: CacheQueryOptions): Promise<boolean>;
76-
match(request: RequestInfo, options?: CacheQueryOptions): Promise<Response | undefined>;
77-
put(request: RequestInfo, response: Response): Promise<void>;
75+
delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<boolean>;
76+
match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise<Response | undefined>;
77+
put(request: RequestInfo | URL, response: Response): Promise<void>;
7878
});
79-
// Use RequestInfo type alias to allow `URL`s as cache keys
8079
}
8180

8281
void visitForMemoryInfo(jsg::MemoryTracker& tracker) const {

src/workerd/api/global-scope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ class ServiceWorkerGlobalScope: public WorkerGlobalScope {
827827

828828
structuredClone<T>(value: T, options?: StructuredSerializeOptions): T;
829829

830-
fetch(input: RequestInfo, init?: RequestInit<RequestInitCfProperties>): Promise<Response>;
830+
fetch(input: RequestInfo | URL, init?: RequestInit<RequestInitCfProperties>): Promise<Response>;
831831
});
832832
}
833833

src/workerd/api/http.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ class Fetcher: public JsRpcClientProvider {
598598
? Rpc.Provider<T, Reserved | "fetch" | "connect" | "queue" | "scheduled">
599599
: unknown
600600
) & {
601-
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
601+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
602602
connect(address: SocketAddress | string, options?: SocketOptions): Socket;
603603
queue(queueName: string, messages: ServiceBindingQueueMessage[]): Promise<FetcherQueueResult>;
604604
scheduled(options?: FetcherScheduledOptions): Promise<FetcherScheduledResult>;
@@ -612,7 +612,7 @@ class Fetcher: public JsRpcClientProvider {
612612
? Rpc.Provider<T, Reserved | "fetch" | "connect">
613613
: unknown
614614
) & {
615-
fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
615+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
616616
connect(address: SocketAddress | string, options?: SocketOptions): Socket;
617617
});
618618
}
@@ -904,7 +904,7 @@ class Request final: public Body {
904904

905905
JSG_METHOD(clone);
906906

907-
JSG_TS_DEFINE(type RequestInfo<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> = Request<CfHostMetadata, Cf> | string | URL);
907+
JSG_TS_DEFINE(type RequestInfo<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> = Request<CfHostMetadata, Cf> | string);
908908
// All type aliases get inlined when exporting RTTI, but this type alias is included by
909909
// the official TypeScript types, so users might be depending on it.
910910

@@ -927,14 +927,14 @@ class Request final: public Body {
927927
if(flags.getCacheOptionEnabled()) {
928928
JSG_READONLY_PROTOTYPE_PROPERTY(cache, getCache);
929929
JSG_TS_OVERRIDE(<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> {
930-
constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
930+
constructor(input: RequestInfo<CfProperties> | URL, init?: RequestInit<Cf>);
931931
clone(): Request<CfHostMetadata, Cf>;
932932
cache?: "no-store";
933933
get cf(): Cf | undefined;
934934
});
935935
} else {
936936
JSG_TS_OVERRIDE(<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> {
937-
constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
937+
constructor(input: RequestInfo<CfProperties> | URL, init?: RequestInit<Cf>);
938938
clone(): Request<CfHostMetadata, Cf>;
939939
get cf(): Cf | undefined;
940940
});
@@ -961,7 +961,7 @@ class Request final: public Body {
961961
JSG_READONLY_INSTANCE_PROPERTY(keepalive, getKeepalive);
962962

963963
JSG_TS_OVERRIDE(<CfHostMetadata = unknown, Cf = CfProperties<CfHostMetadata>> {
964-
constructor(input: RequestInfo<CfProperties>, init?: RequestInit<Cf>);
964+
constructor(input: RequestInfo<CfProperties> | URL, init?: RequestInit<Cf>);
965965
clone(): Request<CfHostMetadata, Cf>;
966966
readonly cf?: Cf;
967967
});

types/test/types/rpc.ts

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ type TestType = {
1414
fieldString: string;
1515
fieldCallback: (p: string) => number;
1616
fieldBasicMap: Map<string, number>;
17-
fieldComplexMap: Map<string, {
18-
fieldString: string;
19-
fieldCallback: (p: string) => number;
20-
}>;
17+
fieldComplexMap: Map<
18+
string,
19+
{
20+
fieldString: string;
21+
fieldCallback: (p: string) => number;
22+
}
23+
>;
2124
fieldSet: Set<string>;
2225
fieldSubLevel: {
2326
fieldString: string;
@@ -28,7 +31,7 @@ type TestType = {
2831
interface ABasicInterface {
2932
fieldString: string;
3033
fieldCallback: (p: string) => number;
31-
};
34+
}
3235

3336
interface TestInterface extends ABasicInterface {
3437
fieldBasicMap: Map<string, number>;
@@ -39,11 +42,11 @@ interface TestInterface extends ABasicInterface {
3942
fieldCallback: (p: string) => number;
4043
};
4144
fieldSubLevelInterface: ABasicInterface;
42-
};
45+
}
4346

4447
interface NonSerializableInterface {
4548
field: ReadableStream<string>;
46-
};
49+
}
4750

4851
class TestCounter extends RpcTarget {
4952
constructor(private val = 0) {
@@ -220,10 +223,15 @@ class TestEntrypoint extends WorkerEntrypoint<Env> {
220223
fieldString: "a",
221224
fieldCallback: (p: string) => 1,
222225
fieldBasicMap: new Map([["b", 2]]),
223-
fieldComplexMap: new Map([["c", {
224-
fieldString: "d",
225-
fieldCallback: (p: string) => 3,
226-
}]]),
226+
fieldComplexMap: new Map([
227+
[
228+
"c",
229+
{
230+
fieldString: "d",
231+
fieldCallback: (p: string) => 3,
232+
},
233+
],
234+
]),
227235
fieldSet: new Set(["e"]),
228236
fieldSubLevel: {
229237
fieldString: "f",
@@ -236,10 +244,15 @@ class TestEntrypoint extends WorkerEntrypoint<Env> {
236244
fieldString: "a",
237245
fieldCallback: (p: string) => 1,
238246
fieldBasicMap: new Map([["b", 2]]),
239-
fieldComplexMap: new Map([["c", {
240-
fieldString: "d",
241-
fieldCallback: (p: string) => 3,
242-
}]]),
247+
fieldComplexMap: new Map([
248+
[
249+
"c",
250+
{
251+
fieldString: "d",
252+
fieldCallback: (p: string) => 3,
253+
},
254+
],
255+
]),
243256
fieldSet: new Set(["e"]),
244257
fieldSubLevelInline: {
245258
fieldString: "f",
@@ -374,7 +387,7 @@ export default <ExportedHandler<Env>>{
374387
// `toEqualTypeOf(...)` will fail if the function signature doesn't match *exactly*)
375388
{
376389
expectTypeOf(env.RPC_SERVICE.fetch).toEqualTypeOf<
377-
(input: RequestInfo, init?: RequestInit) => Promise<Response>
390+
(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
378391
>();
379392
expectTypeOf(env.RPC_SERVICE.connect).toEqualTypeOf<
380393
(address: SocketAddress | string, options?: SocketOptions) => Socket
@@ -391,7 +404,7 @@ export default <ExportedHandler<Env>>{
391404

392405
const stub = env.RPC_OBJECT.get(env.RPC_OBJECT.newUniqueId());
393406
expectTypeOf(stub.fetch).toEqualTypeOf<
394-
(input: RequestInfo, init?: RequestInit) => Promise<Response>
407+
(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
395408
>();
396409
expectTypeOf(stub.connect).toEqualTypeOf<
397410
(address: SocketAddress | string, options?: SocketOptions) => Socket
@@ -520,10 +533,15 @@ export default <ExportedHandler<Env>>{
520533
RpcStub<(p: string) => number>
521534
>(); // stubified
522535
expectTypeOf(oType.fieldBasicMap).toEqualTypeOf<Map<string, number>>();
523-
expectTypeOf(oType.fieldComplexMap).toEqualTypeOf<Map<string, {
524-
fieldString: string;
525-
fieldCallback: RpcStub<(p: string) => number>; // stubified
526-
}>>();
536+
expectTypeOf(oType.fieldComplexMap).toEqualTypeOf<
537+
Map<
538+
string,
539+
{
540+
fieldString: string;
541+
fieldCallback: RpcStub<(p: string) => number>; // stubified
542+
}
543+
>
544+
>();
527545
expectTypeOf(oType.fieldSet).toEqualTypeOf<Set<string>>();
528546
expectTypeOf(oType.fieldSubLevel.fieldString).toEqualTypeOf<string>();
529547
expectTypeOf(oType.fieldSubLevel.fieldCallback).toEqualTypeOf<
@@ -537,20 +555,31 @@ export default <ExportedHandler<Env>>{
537555
expectTypeOf(oInterface.fieldCallback).toEqualTypeOf<
538556
RpcStub<(p: string) => number>
539557
>(); // stubified
540-
expectTypeOf(oInterface.fieldBasicMap).toEqualTypeOf<Map<string, number>>();
541-
expectTypeOf(oInterface.fieldComplexMap).toEqualTypeOf<Map<string, {
542-
fieldString: string;
543-
fieldCallback: RpcStub<(p: string) => number>; // stubified
544-
}>>();
558+
expectTypeOf(oInterface.fieldBasicMap).toEqualTypeOf<
559+
Map<string, number>
560+
>();
561+
expectTypeOf(oInterface.fieldComplexMap).toEqualTypeOf<
562+
Map<
563+
string,
564+
{
565+
fieldString: string;
566+
fieldCallback: RpcStub<(p: string) => number>; // stubified
567+
}
568+
>
569+
>();
545570
expectTypeOf(oInterface.fieldSet).toEqualTypeOf<Set<string>>();
546-
expectTypeOf(oInterface.fieldSubLevelInline.fieldString).toEqualTypeOf<string>();
571+
expectTypeOf(
572+
oInterface.fieldSubLevelInline.fieldString
573+
).toEqualTypeOf<string>();
547574
expectTypeOf(oInterface.fieldSubLevelInline.fieldCallback).toEqualTypeOf<
548575
RpcStub<(p: string) => number>
549576
>(); // stubified
550-
expectTypeOf(oInterface.fieldSubLevelInterface.fieldString).toEqualTypeOf<string>();
551-
expectTypeOf(oInterface.fieldSubLevelInterface.fieldCallback).toEqualTypeOf<
552-
RpcStub<(p: string) => number>
553-
>(); // stubified
577+
expectTypeOf(
578+
oInterface.fieldSubLevelInterface.fieldString
579+
).toEqualTypeOf<string>();
580+
expectTypeOf(
581+
oInterface.fieldSubLevelInterface.fieldCallback
582+
).toEqualTypeOf<RpcStub<(p: string) => number>>(); // stubified
554583

555584
expectTypeOf(s.nonSerializable1).returns.toBeNever();
556585
// Note: Since one of the object's members is non-serializable,

0 commit comments

Comments
 (0)