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:
parent
b5eb154d74
commit
4e71a9424e
5 changed files with 25 additions and 8 deletions
cli
dts
tests
7
cli/dts/lib.deno.window.d.ts
vendored
7
cli/dts/lib.deno.window.d.ts
vendored
|
@ -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;
|
||||
|
||||
|
|
7
cli/dts/lib.deno.worker.d.ts
vendored
7
cli/dts/lib.deno.worker.d.ts
vendored
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
});
|
||||
|
|
|
@ -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();
|
|
@ -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
|
Loading…
Reference in a new issue