|
1 | 1 | // AbortController API types |
2 | 2 |
|
3 | | -/** |
4 | | - * A signal object that allows you to communicate with an async operation |
5 | | - * and abort it if required via an AbortController. |
6 | | - */ |
7 | | -interface AbortSignal extends EventTarget { |
8 | | - /** Returns true if the signal has been aborted. */ |
9 | | - readonly aborted: boolean; |
10 | | - /** The reason for aborting, if any. */ |
11 | | - readonly reason: unknown; |
12 | | - /** Throws the abort reason if the signal has been aborted. */ |
13 | | - throwIfAborted(): void; |
14 | | -} |
| 3 | +export {}; |
| 4 | + |
| 5 | +declare global { |
| 6 | + /** |
| 7 | + * A signal object that allows you to communicate with an async operation |
| 8 | + * and abort it if required via an AbortController. |
| 9 | + */ |
| 10 | + interface AbortSignal extends EventTarget { |
| 11 | + /** Returns true if the signal has been aborted. */ |
| 12 | + readonly aborted: boolean; |
| 13 | + |
| 14 | + /** The reason for aborting, if any. */ |
| 15 | + readonly reason: unknown; |
| 16 | + |
| 17 | + /** Throws the abort reason if the signal has been aborted. */ |
| 18 | + throwIfAborted(): void; |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * A controller object that allows you to abort one or more async operations. |
| 23 | + * |
| 24 | + * @example |
| 25 | + * ```ts |
| 26 | + * const controller = new AbortController(); |
| 27 | + * fetch(url, { signal: controller.signal }); |
| 28 | + * controller.abort(); // Cancels the fetch |
| 29 | + * ``` |
| 30 | + */ |
| 31 | + class AbortController { |
| 32 | + /** The AbortSignal associated with this controller. */ |
| 33 | + readonly signal: AbortSignal; |
15 | 34 |
|
16 | | -/** |
17 | | - * A controller object that allows you to abort one or more async operations. |
18 | | - * |
19 | | - * @example |
20 | | - * ```ts |
21 | | - * const controller = new AbortController(); |
22 | | - * fetch(url, { signal: controller.signal }); |
23 | | - * controller.abort(); // Cancels the fetch |
24 | | - * ``` |
25 | | - */ |
26 | | -declare class AbortController { |
27 | | - /** The AbortSignal associated with this controller. */ |
28 | | - readonly signal: AbortSignal; |
29 | | - /** Aborts the associated signal with an optional reason. */ |
30 | | - abort(reason?: unknown): void; |
| 35 | + /** Aborts the associated signal with an optional reason. */ |
| 36 | + abort(reason?: unknown): void; |
| 37 | + } |
31 | 38 | } |
0 commit comments