Skip to content

Commit

Permalink
fix: add typings for AbortSignal.reason (denoland#12730)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato committed Nov 11, 2021
1 parent e00bfec commit 08067b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cli/tests/unit/abort_controller_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
});
4 changes: 3 additions & 1 deletion ext/web/lib.deno_web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -297,6 +298,7 @@ interface AbortSignal extends EventTarget {
declare var AbortSignal: {
prototype: AbortSignal;
new (): AbortSignal;
abort(reason?: any): AbortSignal;
};

interface FileReaderEventMap {
Expand Down

0 comments on commit 08067b5

Please sign in to comment.