Skip to content

Commit 82f3bb2

Browse files
Add fallback type for AbortSignal
1 parent 8927bc6 commit 82f3bb2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

etc/web-streams-polyfill.api.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export type AbortSignal = typeof globalThis extends {
99
AbortSignal: {
1010
prototype: infer T;
1111
};
12-
} ? T : never;
12+
} ? T : {
13+
aborted: boolean;
14+
readonly reason?: any;
15+
addEventListener(type: 'abort', listener: () => void): void;
16+
removeEventListener(type: 'abort', listener: () => void): void;
17+
};
1318

1419
// @public
1520
export class ByteLengthQueuingStrategy implements QueuingStrategy<ArrayBufferView> {

src/lib/abort-signal.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
*
88
* @public
99
*/
10-
export type AbortSignal = typeof globalThis extends { AbortSignal: { prototype: infer T } } ? T : never;
10+
export type AbortSignal = typeof globalThis extends { AbortSignal: { prototype: infer T } } ? T : {
11+
aborted: boolean;
12+
readonly reason?: any;
13+
addEventListener(type: 'abort', listener: () => void): void;
14+
removeEventListener(type: 'abort', listener: () => void): void;
15+
};
1116

1217
export function isAbortSignal(value: unknown): value is AbortSignal {
1318
if (typeof value !== 'object' || value === null) {
@@ -31,7 +36,10 @@ export function isAbortSignal(value: unknown): value is AbortSignal {
3136
*/
3237
// Trick with globalThis inspired by @types/node
3338
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0c370ead967cb97b1758d8fa15d09011fb3f58ea/types/node/globals.d.ts#L226
34-
export type AbortController = typeof globalThis extends { AbortController: { prototype: infer T } } ? T : never;
39+
export type AbortController = typeof globalThis extends { AbortController: { prototype: infer T } } ? T : {
40+
readonly signal: AbortSignal;
41+
abort(reason?: any): void;
42+
};
3543

3644
/**
3745
* Construct a new AbortController, if supported by the platform.

0 commit comments

Comments
 (0)