1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 12:58:54 -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 {
"error": ErrorEvent;
"unhandledrejection": PromiseRejectionEvent;
}
declare class Window extends EventTarget {
@ -18,6 +19,9 @@ declare class Window extends EventTarget {
onerror: ((this: Window, ev: ErrorEvent) => any) | null;
onload: ((this: Window, ev: Event) => any) | null;
onunload: ((this: Window, ev: Event) => any) | null;
onunhandledrejection:
| ((this: Window, ev: PromiseRejectionEvent) => any)
| null;
close: () => void;
readonly closed: boolean;
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 onload: ((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 sessionStorage: Storage;

View file

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

View file

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

View file

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

View file

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