From 429303bb1089b0dff27755900470b915f8790ff1 Mon Sep 17 00:00:00 2001 From: Katsuyuki Omuro Date: Fri, 10 Oct 2025 15:37:59 +0900 Subject: [PATCH 1/3] Raise TypeScript baseline to 5.9 and adopt generic Uint8Array types --- package-lock.json | 16 ++++++++++++---- package.json | 10 +++++++++- types/cache-override.d.ts | 4 ++-- types/experimental.d.ts | 2 +- types/globals.d.ts | 16 ++++++++-------- types/secret-store.d.ts | 2 +- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 289d470644..edc8b3c2ec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,8 +31,16 @@ "remark-parse": "^11.0.0", "remark-stringify": "^11.0.0", "tsd": "^0.31.1", - "typescript": "^5.5", + "typescript": "^5.9.0", "unified": "^11.0.5" + }, + "peerDependencies": { + "typescript": "^5.9.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } } }, "node_modules/@babel/code-frame": { @@ -5393,9 +5401,9 @@ } }, "node_modules/typescript": { - "version": "5.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", - "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package.json b/package.json index 0562234454..06768dfa22 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "remark-parse": "^11.0.0", "remark-stringify": "^11.0.0", "tsd": "^0.31.1", - "typescript": "^5.5", + "typescript": "^5.9.0", "unified": "^11.0.5" }, "dependencies": { @@ -64,5 +64,13 @@ "esbuild": "^0.25.0", "magic-string": "^0.30.12", "regexpu-core": "^6.1.1" + }, + "peerDependencies": { + "typescript": "^5.9.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } } } diff --git a/types/cache-override.d.ts b/types/cache-override.d.ts index 68756bc9f4..36b60bcaeb 100644 --- a/types/cache-override.d.ts +++ b/types/cache-override.d.ts @@ -37,8 +37,8 @@ declare module 'fastly:cache-override' { * to return the new body. */ bodyTransformFn?: ( - body: Uint8Array, - ) => Uint8Array | PromiseLike; + body: Uint8Array, + ) => Uint8Array | PromiseLike>; } /** * The cache override mode for a request diff --git a/types/experimental.d.ts b/types/experimental.d.ts index 1178087b64..5d49421199 100644 --- a/types/experimental.d.ts +++ b/types/experimental.d.ts @@ -46,7 +46,7 @@ declare module 'fastly:experimental' { * **Note**: Can only be used during build-time initialization, not when processing requests. * @experimental */ - export function includeBytes(path: string): Uint8Array; + export function includeBytes(path: string): Uint8Array; /** * Whether or not to allow Dynamic Backends. diff --git a/types/globals.d.ts b/types/globals.d.ts index ad9ac908ab..e28e773d62 100644 --- a/types/globals.d.ts +++ b/types/globals.d.ts @@ -843,7 +843,7 @@ declare class TextEncoder { * UTF-8 encodes the `input` string and returns a `Uint8Array` containing the encoded bytes. * @param [input='an empty string'] The text to encode. */ - encode(input?: string): Uint8Array; + encode(input?: string): Uint8Array; // /** // * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object // * containing the read Unicode code units and written UTF-8 bytes. @@ -998,7 +998,7 @@ declare interface Fastly { * @hidden * @experimental */ - includeBytes(path: string): Uint8Array; + includeBytes(path: string): Uint8Array; } /** @@ -1055,7 +1055,7 @@ declare class CompressionStream { * console.log(stream.readable instanceof ReadableStream); // true * ``` */ - readonly readable: ReadableStream; + readonly readable: ReadableStream>; /** * @example * ```js @@ -1063,7 +1063,7 @@ declare class CompressionStream { * console.log(stream.writable instanceof WritableStream); // true * ``` */ - readonly writable: WritableStream; + readonly writable: WritableStream>; } /** @@ -1110,7 +1110,7 @@ declare class DecompressionStream { * console.log(stream.readable instanceof ReadableStream); // true * ``` */ - readonly readable: ReadableStream; + readonly readable: ReadableStream>; /** * @example * ```js @@ -1118,7 +1118,7 @@ declare class DecompressionStream { * console.log(stream.writable instanceof WritableStream); // true * ``` */ - readonly writable: WritableStream; + readonly writable: WritableStream>; } // Note: the contents below here are, partially modified, copies of content from TypeScript's @@ -1175,7 +1175,7 @@ interface Blob { /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */ slice(start?: number, end?: number, contentType?: string): Blob; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */ - stream(): ReadableStream; + stream(): ReadableStream>; /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */ text(): Promise; } @@ -1265,7 +1265,7 @@ declare type XMLHttpRequestBodyInit = * @group Fetch API */ declare interface Body { - readonly body: ReadableStream | null; + readonly body: ReadableStream> | null; readonly bodyUsed: boolean; arrayBuffer(): Promise; blob(): Promise; diff --git a/types/secret-store.d.ts b/types/secret-store.d.ts index f149f84c36..3219f6ac4f 100644 --- a/types/secret-store.d.ts +++ b/types/secret-store.d.ts @@ -39,6 +39,6 @@ declare module 'fastly:secret-store' { * always avoid using this method when possible, instead passing * the secret directly. */ - rawBytes(): Uint8Array; + rawBytes(): Uint8Array; } } From ceaefc73e253e18667ff4d8e96c4dfbebbaff641 Mon Sep 17 00:00:00 2001 From: Katsuyuki Omuro Date: Sat, 11 Oct 2025 18:48:54 +0900 Subject: [PATCH 2/3] Update tsd to 0.33, which introduces TS5.9 support --- package-lock.json | 16 ++++++++-------- package.json | 2 +- test-d/experimental.test-d.ts | 2 +- test-d/globals.test-d.ts | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index edc8b3c2ec..ad0186773f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,7 +30,7 @@ "prettier": "^3.3.3", "remark-parse": "^11.0.0", "remark-stringify": "^11.0.0", - "tsd": "^0.31.1", + "tsd": "^0.33.0", "typescript": "^5.9.0", "unified": "^11.0.5" }, @@ -1374,9 +1374,9 @@ "license": "MIT" }, "node_modules/@tsd/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/@tsd/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-saiCxzHRhUrRxQV2JhH580aQUZiKQUXI38FcAcikcfOomAil4G4lxT0RfrrKywoAYP/rqAdYXYmNRLppcd+hQQ==", + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/@tsd/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-JSSdNiS0wgd8GHhBwnMAI18Y8XPhLVN+dNelPfZCXFhy9Lb3NbnFyp9JKxxr54jSUkEJPk3cidvCoHducSaRMQ==", "dev": true, "license": "MIT", "engines": { @@ -5346,13 +5346,13 @@ } }, "node_modules/tsd": { - "version": "0.31.2", - "resolved": "https://registry.npmjs.org/tsd/-/tsd-0.31.2.tgz", - "integrity": "sha512-VplBAQwvYrHzVihtzXiUVXu5bGcr7uH1juQZ1lmKgkuGNGT+FechUCqmx9/zk7wibcqR2xaNEwCkDyKh+VVZnQ==", + "version": "0.33.0", + "resolved": "https://registry.npmjs.org/tsd/-/tsd-0.33.0.tgz", + "integrity": "sha512-/PQtykJFVw90QICG7zyPDMIyueOXKL7jOJVoX5pILnb3Ux+7QqynOxfVvarE+K+yi7BZyOSY4r+OZNWSWRiEwQ==", "dev": true, "license": "MIT", "dependencies": { - "@tsd/typescript": "~5.4.3", + "@tsd/typescript": "^5.9.2", "eslint-formatter-pretty": "^4.1.0", "globby": "^11.0.1", "jest-diff": "^29.0.3", diff --git a/package.json b/package.json index 06768dfa22..3c856055e9 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "prettier": "^3.3.3", "remark-parse": "^11.0.0", "remark-stringify": "^11.0.0", - "tsd": "^0.31.1", + "tsd": "^0.33.0", "typescript": "^5.9.0", "unified": "^11.0.5" }, diff --git a/test-d/experimental.test-d.ts b/test-d/experimental.test-d.ts index f1dea9fae0..7d5360a7ce 100644 --- a/test-d/experimental.test-d.ts +++ b/test-d/experimental.test-d.ts @@ -8,7 +8,7 @@ import { } from 'fastly:experimental'; import { expectType } from 'tsd'; -expectType<(path: string) => Uint8Array>(includeBytes); +expectType<(path: string) => Uint8Array>(includeBytes); expectType<(enabled: boolean) => void>(enableDebugLogging); expectType<(base: URL | null | undefined) => void>(setBaseURL); expectType<(backend: string) => void>(setDefaultBackend); diff --git a/test-d/globals.test-d.ts b/test-d/globals.test-d.ts index db52394394..254189e9e1 100644 --- a/test-d/globals.test-d.ts +++ b/test-d/globals.test-d.ts @@ -458,7 +458,7 @@ import { expectError, expectType } from 'tsd'; expectError(new TextEncoder('')); const encoder = new TextEncoder(); expectType(encoder); - expectType<(input?: string) => Uint8Array>(encoder.encode); + expectType<(input?: string) => Uint8Array>(encoder.encode); expectType<'utf-8'>(encoder.encoding); expectError((encoder.encoding = 'd')); } @@ -484,7 +484,7 @@ import { expectError, expectType } from 'tsd'; expectType<(address: string) => Geolocation>( fastly.getGeolocationForIpAddress, ); - expectType<(path: string) => Uint8Array>(fastly.includeBytes); + expectType<(path: string) => Uint8Array>(fastly.includeBytes); } // CompressionStream @@ -494,9 +494,9 @@ import { expectError, expectType } from 'tsd'; let stream = new CompressionStream('deflate'); stream = new CompressionStream('deflate-raw'); stream = new CompressionStream('gzip'); - expectType>(stream.readable); + expectType>>(stream.readable); expectError((stream.readable = 'd')); - expectType>(stream.writable); + expectType>>(stream.writable); expectError((stream.writable = 'd')); } @@ -507,8 +507,8 @@ import { expectError, expectType } from 'tsd'; let stream = new DecompressionStream('deflate'); stream = new DecompressionStream('deflate-raw'); stream = new DecompressionStream('gzip'); - expectType>(stream.readable); + expectType>>(stream.readable); expectError((stream.readable = 'd')); - expectType>(stream.writable); + expectType>>(stream.writable); expectError((stream.writable = 'd')); } From c08d13ea6db41106da9807dffdcdecf7cb8e9088 Mon Sep 17 00:00:00 2001 From: Katsuyuki Omuro Date: Sat, 11 Oct 2025 18:55:37 +0900 Subject: [PATCH 3/3] Correct a type test that breaks under new tsd --- test-d/globals.test-d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test-d/globals.test-d.ts b/test-d/globals.test-d.ts index 254189e9e1..cd176c71cc 100644 --- a/test-d/globals.test-d.ts +++ b/test-d/globals.test-d.ts @@ -390,7 +390,8 @@ import { expectError, expectType } from 'tsd'; expectType( new URLSearchParams({ [Symbol.iterator]: function* () { - yield ''; + yield ['', '']; + return; }, }), );