diff --git a/src/workerd/api/cache.h b/src/workerd/api/cache.h index 398e81908aa..031005820b6 100644 --- a/src/workerd/api/cache.h +++ b/src/workerd/api/cache.h @@ -72,11 +72,10 @@ class Cache: public jsg::Object { JSG_METHOD(keys); JSG_TS_OVERRIDE({ - delete(request: RequestInfo, options?: CacheQueryOptions): Promise; - match(request: RequestInfo, options?: CacheQueryOptions): Promise; - put(request: RequestInfo, response: Response): Promise; + delete(request: RequestInfo | URL, options?: CacheQueryOptions): Promise; + match(request: RequestInfo | URL, options?: CacheQueryOptions): Promise; + put(request: RequestInfo | URL, response: Response): Promise; }); - // Use RequestInfo type alias to allow `URL`s as cache keys } void visitForMemoryInfo(jsg::MemoryTracker& tracker) const { diff --git a/src/workerd/api/global-scope.h b/src/workerd/api/global-scope.h index c34a5d94cb6..d13fb4cb3f5 100644 --- a/src/workerd/api/global-scope.h +++ b/src/workerd/api/global-scope.h @@ -827,7 +827,7 @@ class ServiceWorkerGlobalScope: public WorkerGlobalScope { structuredClone(value: T, options?: StructuredSerializeOptions): T; - fetch(input: RequestInfo, init?: RequestInit): Promise; + fetch(input: RequestInfo | URL, init?: RequestInit): Promise; }); } diff --git a/src/workerd/api/http.h b/src/workerd/api/http.h index 1093c5e4149..3ecc5b926cb 100644 --- a/src/workerd/api/http.h +++ b/src/workerd/api/http.h @@ -598,7 +598,7 @@ class Fetcher: public JsRpcClientProvider { ? Rpc.Provider : unknown ) & { - fetch(input: RequestInfo, init?: RequestInit): Promise; + fetch(input: RequestInfo | URL, init?: RequestInit): Promise; connect(address: SocketAddress | string, options?: SocketOptions): Socket; queue(queueName: string, messages: ServiceBindingQueueMessage[]): Promise; scheduled(options?: FetcherScheduledOptions): Promise; @@ -612,7 +612,7 @@ class Fetcher: public JsRpcClientProvider { ? Rpc.Provider : unknown ) & { - fetch(input: RequestInfo, init?: RequestInit): Promise; + fetch(input: RequestInfo | URL, init?: RequestInit): Promise; connect(address: SocketAddress | string, options?: SocketOptions): Socket; }); } @@ -904,7 +904,7 @@ class Request final: public Body { JSG_METHOD(clone); - JSG_TS_DEFINE(type RequestInfo> = Request | string | URL); + JSG_TS_DEFINE(type RequestInfo> = Request | string); // All type aliases get inlined when exporting RTTI, but this type alias is included by // the official TypeScript types, so users might be depending on it. @@ -927,14 +927,14 @@ class Request final: public Body { if(flags.getCacheOptionEnabled()) { JSG_READONLY_PROTOTYPE_PROPERTY(cache, getCache); JSG_TS_OVERRIDE(> { - constructor(input: RequestInfo, init?: RequestInit); + constructor(input: RequestInfo | URL, init?: RequestInit); clone(): Request; cache?: "no-store"; get cf(): Cf | undefined; }); } else { JSG_TS_OVERRIDE(> { - constructor(input: RequestInfo, init?: RequestInit); + constructor(input: RequestInfo | URL, init?: RequestInit); clone(): Request; get cf(): Cf | undefined; }); @@ -961,7 +961,7 @@ class Request final: public Body { JSG_READONLY_INSTANCE_PROPERTY(keepalive, getKeepalive); JSG_TS_OVERRIDE(> { - constructor(input: RequestInfo, init?: RequestInit); + constructor(input: RequestInfo | URL, init?: RequestInit); clone(): Request; readonly cf?: Cf; }); diff --git a/types/test/types/rpc.ts b/types/test/types/rpc.ts index c172bf0de0e..4307bb94692 100644 --- a/types/test/types/rpc.ts +++ b/types/test/types/rpc.ts @@ -14,10 +14,13 @@ type TestType = { fieldString: string; fieldCallback: (p: string) => number; fieldBasicMap: Map; - fieldComplexMap: Map number; - }>; + fieldComplexMap: Map< + string, + { + fieldString: string; + fieldCallback: (p: string) => number; + } + >; fieldSet: Set; fieldSubLevel: { fieldString: string; @@ -28,7 +31,7 @@ type TestType = { interface ABasicInterface { fieldString: string; fieldCallback: (p: string) => number; -}; +} interface TestInterface extends ABasicInterface { fieldBasicMap: Map; @@ -39,11 +42,11 @@ interface TestInterface extends ABasicInterface { fieldCallback: (p: string) => number; }; fieldSubLevelInterface: ABasicInterface; -}; +} interface NonSerializableInterface { field: ReadableStream; -}; +} class TestCounter extends RpcTarget { constructor(private val = 0) { @@ -220,10 +223,15 @@ class TestEntrypoint extends WorkerEntrypoint { fieldString: "a", fieldCallback: (p: string) => 1, fieldBasicMap: new Map([["b", 2]]), - fieldComplexMap: new Map([["c", { - fieldString: "d", - fieldCallback: (p: string) => 3, - }]]), + fieldComplexMap: new Map([ + [ + "c", + { + fieldString: "d", + fieldCallback: (p: string) => 3, + }, + ], + ]), fieldSet: new Set(["e"]), fieldSubLevel: { fieldString: "f", @@ -236,10 +244,15 @@ class TestEntrypoint extends WorkerEntrypoint { fieldString: "a", fieldCallback: (p: string) => 1, fieldBasicMap: new Map([["b", 2]]), - fieldComplexMap: new Map([["c", { - fieldString: "d", - fieldCallback: (p: string) => 3, - }]]), + fieldComplexMap: new Map([ + [ + "c", + { + fieldString: "d", + fieldCallback: (p: string) => 3, + }, + ], + ]), fieldSet: new Set(["e"]), fieldSubLevelInline: { fieldString: "f", @@ -374,7 +387,7 @@ export default >{ // `toEqualTypeOf(...)` will fail if the function signature doesn't match *exactly*) { expectTypeOf(env.RPC_SERVICE.fetch).toEqualTypeOf< - (input: RequestInfo, init?: RequestInit) => Promise + (input: RequestInfo | URL, init?: RequestInit) => Promise >(); expectTypeOf(env.RPC_SERVICE.connect).toEqualTypeOf< (address: SocketAddress | string, options?: SocketOptions) => Socket @@ -391,7 +404,7 @@ export default >{ const stub = env.RPC_OBJECT.get(env.RPC_OBJECT.newUniqueId()); expectTypeOf(stub.fetch).toEqualTypeOf< - (input: RequestInfo, init?: RequestInit) => Promise + (input: RequestInfo | URL, init?: RequestInit) => Promise >(); expectTypeOf(stub.connect).toEqualTypeOf< (address: SocketAddress | string, options?: SocketOptions) => Socket @@ -520,10 +533,15 @@ export default >{ RpcStub<(p: string) => number> >(); // stubified expectTypeOf(oType.fieldBasicMap).toEqualTypeOf>(); - expectTypeOf(oType.fieldComplexMap).toEqualTypeOf number>; // stubified - }>>(); + expectTypeOf(oType.fieldComplexMap).toEqualTypeOf< + Map< + string, + { + fieldString: string; + fieldCallback: RpcStub<(p: string) => number>; // stubified + } + > + >(); expectTypeOf(oType.fieldSet).toEqualTypeOf>(); expectTypeOf(oType.fieldSubLevel.fieldString).toEqualTypeOf(); expectTypeOf(oType.fieldSubLevel.fieldCallback).toEqualTypeOf< @@ -537,20 +555,31 @@ export default >{ expectTypeOf(oInterface.fieldCallback).toEqualTypeOf< RpcStub<(p: string) => number> >(); // stubified - expectTypeOf(oInterface.fieldBasicMap).toEqualTypeOf>(); - expectTypeOf(oInterface.fieldComplexMap).toEqualTypeOf number>; // stubified - }>>(); + expectTypeOf(oInterface.fieldBasicMap).toEqualTypeOf< + Map + >(); + expectTypeOf(oInterface.fieldComplexMap).toEqualTypeOf< + Map< + string, + { + fieldString: string; + fieldCallback: RpcStub<(p: string) => number>; // stubified + } + > + >(); expectTypeOf(oInterface.fieldSet).toEqualTypeOf>(); - expectTypeOf(oInterface.fieldSubLevelInline.fieldString).toEqualTypeOf(); + expectTypeOf( + oInterface.fieldSubLevelInline.fieldString + ).toEqualTypeOf(); expectTypeOf(oInterface.fieldSubLevelInline.fieldCallback).toEqualTypeOf< RpcStub<(p: string) => number> >(); // stubified - expectTypeOf(oInterface.fieldSubLevelInterface.fieldString).toEqualTypeOf(); - expectTypeOf(oInterface.fieldSubLevelInterface.fieldCallback).toEqualTypeOf< - RpcStub<(p: string) => number> - >(); // stubified + expectTypeOf( + oInterface.fieldSubLevelInterface.fieldString + ).toEqualTypeOf(); + expectTypeOf( + oInterface.fieldSubLevelInterface.fieldCallback + ).toEqualTypeOf number>>(); // stubified expectTypeOf(s.nonSerializable1).returns.toBeNever(); // Note: Since one of the object's members is non-serializable,