1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-05 13:59:01 -05:00

fix: proper typings for unhandledrejection event (#15271)

This commit is contained in:
Bartek Iwańczuk 2022-07-21 23:54:53 +02:00 committed by GitHub
parent b5eb154d74
commit 4e71a9424e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 8 deletions

View file

@ -9,6 +9,7 @@
interface WindowEventMap { interface WindowEventMap {
"error": ErrorEvent; "error": ErrorEvent;
"unhandledrejection": PromiseRejectionEvent;
} }
declare class Window extends EventTarget { declare class Window extends EventTarget {
@ -18,6 +19,9 @@ declare class Window extends EventTarget {
onerror: ((this: Window, ev: ErrorEvent) => any) | null; onerror: ((this: Window, ev: ErrorEvent) => any) | null;
onload: ((this: Window, ev: Event) => any) | null; onload: ((this: Window, ev: Event) => any) | null;
onunload: ((this: Window, ev: Event) => any) | null; onunload: ((this: Window, ev: Event) => any) | null;
onunhandledrejection:
| ((this: Window, ev: PromiseRejectionEvent) => any)
| null;
close: () => void; close: () => void;
readonly closed: boolean; readonly closed: boolean;
alert: (message?: string) => void; alert: (message?: string) => void;
@ -64,6 +68,9 @@ declare var self: Window & typeof globalThis;
declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null; declare var onerror: ((this: Window, ev: ErrorEvent) => any) | null;
declare var onload: ((this: Window, ev: Event) => any) | null; declare var onload: ((this: Window, ev: Event) => any) | null;
declare var onunload: ((this: Window, ev: Event) => any) | null; declare var onunload: ((this: Window, ev: Event) => any) | null;
declare var onunhandledrejection:
| ((this: Window, ev: PromiseRejectionEvent) => any)
| null;
declare var localStorage: Storage; declare var localStorage: Storage;
declare var sessionStorage: Storage; declare var sessionStorage: Storage;

View file

@ -8,12 +8,16 @@
interface WorkerGlobalScopeEventMap { interface WorkerGlobalScopeEventMap {
"error": ErrorEvent; "error": ErrorEvent;
"unhandledrejection": PromiseRejectionEvent;
} }
declare class WorkerGlobalScope extends EventTarget { declare class WorkerGlobalScope extends EventTarget {
readonly location: WorkerLocation; readonly location: WorkerLocation;
readonly navigator: WorkerNavigator; readonly navigator: WorkerNavigator;
onerror: ((this: WorkerGlobalScope, ev: ErrorEvent) => any) | null; onerror: ((this: WorkerGlobalScope, ev: ErrorEvent) => any) | null;
onunhandledrejection:
| ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any)
| null;
readonly self: WorkerGlobalScope & typeof globalThis; readonly self: WorkerGlobalScope & typeof globalThis;
@ -117,6 +121,9 @@ declare var navigator: WorkerNavigator;
declare var onerror: declare var onerror:
| ((this: DedicatedWorkerGlobalScope, ev: ErrorEvent) => any) | ((this: DedicatedWorkerGlobalScope, ev: ErrorEvent) => any)
| null; | null;
declare var onunhandledrejection:
| ((this: DedicatedWorkerGlobalScope, ev: PromiseRejectionEvent) => any)
| null;
declare var self: WorkerGlobalScope & typeof globalThis; declare var self: WorkerGlobalScope & typeof globalThis;
declare function addEventListener< declare function addEventListener<
K extends keyof DedicatedWorkerGlobalScopeEventMap, K extends keyof DedicatedWorkerGlobalScopeEventMap,

View file

@ -2784,6 +2784,6 @@ itest!(followup_dyn_import_resolved {
}); });
itest!(unhandled_rejection { itest!(unhandled_rejection {
args: "run --allow-read unhandled_rejection.js", args: "run --check unhandled_rejection.ts",
output: "unhandled_rejection.js.out", output: "unhandled_rejection.ts.out",
}); });

View file

@ -3,8 +3,10 @@ globalThis.addEventListener("unhandledrejection", (e) => {
e.preventDefault(); e.preventDefault();
}); });
function Foo() { class Foo {
this.bar = Promise.reject(new Error("bar not available")); constructor() {
Promise.reject(new Error("bar not available"));
}
} }
new Foo(); new Foo();

View file

@ -1,8 +1,9 @@
[WILDCARD]
unhandled rejection at: Promise { unhandled rejection at: Promise {
<rejected> Error: bar not available <rejected> Error: bar not available
at new Foo (file:///[WILDCARD]/testdata/unhandled_rejection.js:7:29) at new Foo (file:///[WILDCARD]/testdata/unhandled_rejection.ts:8:20)
at file:///[WILDCARD]/testdata/unhandled_rejection.js:10:1 at file:///[WILDCARD]/testdata/unhandled_rejection.ts:12:1
} reason: Error: bar not available } reason: Error: bar not available
at new Foo (file:///[WILDCARD]/testdata/unhandled_rejection.js:7:29) at new Foo (file:///[WILDCARD]/testdata/unhandled_rejection.ts:8:20)
at file:///[WILDCARD]/testdata/unhandled_rejection.js:10:1 at file:///[WILDCARD]/testdata/unhandled_rejection.ts:12:1
unhandled rejection at: Promise { <rejected> undefined } reason: undefined unhandled rejection at: Promise { <rejected> undefined } reason: undefined