diff options
author | Luca Casonato <hello@lcas.dev> | 2021-11-11 10:28:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-11 10:28:06 +0100 |
commit | 08067b5e12dc8d486c42e3997dbfd0766666ecb5 (patch) | |
tree | c5b0da64c9095e238c2aea3bef5a1aaf724bcad1 | |
parent | e00bfecf960a7d1c60542e04d17c4e558083f8e9 (diff) |
fix: add typings for AbortSignal.reason (#12730)
-rw-r--r-- | cli/tests/unit/abort_controller_test.ts | 6 | ||||
-rw-r--r-- | ext/web/lib.deno_web.d.ts | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/cli/tests/unit/abort_controller_test.ts b/cli/tests/unit/abort_controller_test.ts index 46c0e9394..50a17ad24 100644 --- a/cli/tests/unit/abort_controller_test.ts +++ b/cli/tests/unit/abort_controller_test.ts @@ -54,3 +54,9 @@ unitTest(function controllerHasProperToString() { const actual = Object.prototype.toString.call(new AbortController()); assertEquals(actual, "[object AbortController]"); }); + +unitTest(function abortReason() { + const signal = AbortSignal.abort("hey!"); + assertEquals(signal.aborted, true); + assertEquals(signal.reason, "hey!"); +}); diff --git a/ext/web/lib.deno_web.d.ts b/ext/web/lib.deno_web.d.ts index 8440045b8..f388fba0c 100644 --- a/ext/web/lib.deno_web.d.ts +++ b/ext/web/lib.deno_web.d.ts @@ -258,7 +258,7 @@ declare class AbortController { readonly signal: AbortSignal; /** Invoking this method will set this object's AbortSignal's aborted flag and * signal to any observers that the associated activity is to be aborted. */ - abort(): void; + abort(reason?: any): void; } interface AbortSignalEventMap { @@ -271,6 +271,7 @@ interface AbortSignal extends EventTarget { /** Returns true if this AbortSignal's AbortController has signaled to abort, * and false otherwise. */ readonly aborted: boolean; + readonly reason?: unknown; onabort: ((this: AbortSignal, ev: Event) => any) | null; addEventListener<K extends keyof AbortSignalEventMap>( type: K, @@ -297,6 +298,7 @@ interface AbortSignal extends EventTarget { declare var AbortSignal: { prototype: AbortSignal; new (): AbortSignal; + abort(reason?: any): AbortSignal; }; interface FileReaderEventMap { |