Skip to content

Commit 33fd9ef

Browse files
authored
chore: Raise TypeScript baseline to 5.9 and adopt generic Uint8Array types. (#1208)
1 parent 92ab5c6 commit 33fd9ef

File tree

8 files changed

+51
-34
lines changed

8 files changed

+51
-34
lines changed

package-lock.json

Lines changed: 20 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"prettier": "^3.3.3",
5252
"remark-parse": "^11.0.0",
5353
"remark-stringify": "^11.0.0",
54-
"tsd": "^0.31.1",
55-
"typescript": "^5.5",
54+
"tsd": "^0.33.0",
55+
"typescript": "^5.9.0",
5656
"unified": "^11.0.5"
5757
},
5858
"dependencies": {
@@ -64,5 +64,13 @@
6464
"esbuild": "^0.25.0",
6565
"magic-string": "^0.30.12",
6666
"regexpu-core": "^6.1.1"
67+
},
68+
"peerDependencies": {
69+
"typescript": "^5.9.0"
70+
},
71+
"peerDependenciesMeta": {
72+
"typescript": {
73+
"optional": true
74+
}
6775
}
6876
}

test-d/experimental.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'fastly:experimental';
99
import { expectType } from 'tsd';
1010

11-
expectType<(path: string) => Uint8Array>(includeBytes);
11+
expectType<(path: string) => Uint8Array<ArrayBuffer>>(includeBytes);
1212
expectType<(enabled: boolean) => void>(enableDebugLogging);
1313
expectType<(base: URL | null | undefined) => void>(setBaseURL);
1414
expectType<(backend: string) => void>(setDefaultBackend);

test-d/globals.test-d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ import { expectError, expectType } from 'tsd';
390390
expectType<URLSearchParams>(
391391
new URLSearchParams({
392392
[Symbol.iterator]: function* () {
393-
yield '';
393+
yield ['', ''];
394+
return;
394395
},
395396
}),
396397
);
@@ -458,7 +459,7 @@ import { expectError, expectType } from 'tsd';
458459
expectError(new TextEncoder(''));
459460
const encoder = new TextEncoder();
460461
expectType<TextEncoder>(encoder);
461-
expectType<(input?: string) => Uint8Array>(encoder.encode);
462+
expectType<(input?: string) => Uint8Array<ArrayBuffer>>(encoder.encode);
462463
expectType<'utf-8'>(encoder.encoding);
463464
expectError((encoder.encoding = 'd'));
464465
}
@@ -484,7 +485,7 @@ import { expectError, expectType } from 'tsd';
484485
expectType<(address: string) => Geolocation>(
485486
fastly.getGeolocationForIpAddress,
486487
);
487-
expectType<(path: string) => Uint8Array>(fastly.includeBytes);
488+
expectType<(path: string) => Uint8Array<ArrayBuffer>>(fastly.includeBytes);
488489
}
489490

490491
// CompressionStream
@@ -494,9 +495,9 @@ import { expectError, expectType } from 'tsd';
494495
let stream = new CompressionStream('deflate');
495496
stream = new CompressionStream('deflate-raw');
496497
stream = new CompressionStream('gzip');
497-
expectType<ReadableStream<Uint8Array>>(stream.readable);
498+
expectType<ReadableStream<Uint8Array<ArrayBuffer>>>(stream.readable);
498499
expectError((stream.readable = 'd'));
499-
expectType<WritableStream<Uint8Array>>(stream.writable);
500+
expectType<WritableStream<Uint8Array<ArrayBuffer>>>(stream.writable);
500501
expectError((stream.writable = 'd'));
501502
}
502503

@@ -507,8 +508,8 @@ import { expectError, expectType } from 'tsd';
507508
let stream = new DecompressionStream('deflate');
508509
stream = new DecompressionStream('deflate-raw');
509510
stream = new DecompressionStream('gzip');
510-
expectType<ReadableStream<Uint8Array>>(stream.readable);
511+
expectType<ReadableStream<Uint8Array<ArrayBuffer>>>(stream.readable);
511512
expectError((stream.readable = 'd'));
512-
expectType<WritableStream<Uint8Array>>(stream.writable);
513+
expectType<WritableStream<Uint8Array<ArrayBuffer>>>(stream.writable);
513514
expectError((stream.writable = 'd'));
514515
}

types/cache-override.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ declare module 'fastly:cache-override' {
3737
* to return the new body.
3838
*/
3939
bodyTransformFn?: (
40-
body: Uint8Array,
41-
) => Uint8Array | PromiseLike<Uint8Array>;
40+
body: Uint8Array<ArrayBuffer>,
41+
) => Uint8Array<ArrayBuffer> | PromiseLike<Uint8Array<ArrayBuffer>>;
4242
}
4343
/**
4444
* The cache override mode for a request

types/experimental.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ declare module 'fastly:experimental' {
4646
* **Note**: Can only be used during build-time initialization, not when processing requests.
4747
* @experimental
4848
*/
49-
export function includeBytes(path: string): Uint8Array;
49+
export function includeBytes(path: string): Uint8Array<ArrayBuffer>;
5050

5151
/**
5252
* Whether or not to allow Dynamic Backends.

types/globals.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ declare class TextEncoder {
843843
* UTF-8 encodes the `input` string and returns a `Uint8Array` containing the encoded bytes.
844844
* @param [input='an empty string'] The text to encode.
845845
*/
846-
encode(input?: string): Uint8Array;
846+
encode(input?: string): Uint8Array<ArrayBuffer>;
847847
// /**
848848
// * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
849849
// * containing the read Unicode code units and written UTF-8 bytes.
@@ -998,7 +998,7 @@ declare interface Fastly {
998998
* @hidden
999999
* @experimental
10001000
*/
1001-
includeBytes(path: string): Uint8Array;
1001+
includeBytes(path: string): Uint8Array<ArrayBuffer>;
10021002
}
10031003

10041004
/**
@@ -1055,15 +1055,15 @@ declare class CompressionStream {
10551055
* console.log(stream.readable instanceof ReadableStream); // true
10561056
* ```
10571057
*/
1058-
readonly readable: ReadableStream<Uint8Array>;
1058+
readonly readable: ReadableStream<Uint8Array<ArrayBuffer>>;
10591059
/**
10601060
* @example
10611061
* ```js
10621062
* let stream = new CompressionStream("gzip");
10631063
* console.log(stream.writable instanceof WritableStream); // true
10641064
* ```
10651065
*/
1066-
readonly writable: WritableStream<Uint8Array>;
1066+
readonly writable: WritableStream<Uint8Array<ArrayBuffer>>;
10671067
}
10681068

10691069
/**
@@ -1110,15 +1110,15 @@ declare class DecompressionStream {
11101110
* console.log(stream.readable instanceof ReadableStream); // true
11111111
* ```
11121112
*/
1113-
readonly readable: ReadableStream<Uint8Array>;
1113+
readonly readable: ReadableStream<Uint8Array<ArrayBuffer>>;
11141114
/**
11151115
* @example
11161116
* ```js
11171117
* let stream = new DecompressionStream("gzip");
11181118
* console.log(stream.writable instanceof WritableStream); // true
11191119
* ```
11201120
*/
1121-
readonly writable: WritableStream<Uint8Array>;
1121+
readonly writable: WritableStream<Uint8Array<ArrayBuffer>>;
11221122
}
11231123

11241124
// Note: the contents below here are, partially modified, copies of content from TypeScript's
@@ -1175,7 +1175,7 @@ interface Blob {
11751175
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/slice) */
11761176
slice(start?: number, end?: number, contentType?: string): Blob;
11771177
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/stream) */
1178-
stream(): ReadableStream<Uint8Array>;
1178+
stream(): ReadableStream<Uint8Array<ArrayBuffer>>;
11791179
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Blob/text) */
11801180
text(): Promise<string>;
11811181
}
@@ -1265,7 +1265,7 @@ declare type XMLHttpRequestBodyInit =
12651265
* @group Fetch API
12661266
*/
12671267
declare interface Body {
1268-
readonly body: ReadableStream<Uint8Array> | null;
1268+
readonly body: ReadableStream<Uint8Array<ArrayBuffer>> | null;
12691269
readonly bodyUsed: boolean;
12701270
arrayBuffer(): Promise<ArrayBuffer>;
12711271
blob(): Promise<Blob>;

types/secret-store.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ declare module 'fastly:secret-store' {
3939
* always avoid using this method when possible, instead passing
4040
* the secret directly.
4141
*/
42-
rawBytes(): Uint8Array;
42+
rawBytes(): Uint8Array<ArrayBuffer>;
4343
}
4444
}

0 commit comments

Comments
 (0)