summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-07-21 23:54:53 +0200
committerGitHub <noreply@github.com>2022-07-21 23:54:53 +0200
commit4e71a9424e12a9711b41edce049ee026f0a904b4 (patch)
tree7d0bfac4cd787fd6fbe0ec37881a81d607904674
parentb5eb154d74d3ccb1a5f4fcc4f073ebd841bb904e (diff)
fix: proper typings for unhandledrejection event (#15271)
-rw-r--r--cli/dts/lib.deno.window.d.ts7
-rw-r--r--cli/dts/lib.deno.worker.d.ts7
-rw-r--r--cli/tests/integration/run_tests.rs4
-rw-r--r--cli/tests/testdata/unhandled_rejection.ts (renamed from cli/tests/testdata/unhandled_rejection.js)6
-rw-r--r--cli/tests/testdata/unhandled_rejection.ts.out (renamed from cli/tests/testdata/unhandled_rejection.js.out)9
5 files changed, 25 insertions, 8 deletions
diff --git a/cli/dts/lib.deno.window.d.ts b/cli/dts/lib.deno.window.d.ts
index 1600b0eac..1dbfb0493 100644
--- a/cli/dts/lib.deno.window.d.ts
+++ b/cli/dts/lib.deno.window.d.ts
@@ -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;
diff --git a/cli/dts/lib.deno.worker.d.ts b/cli/dts/lib.deno.worker.d.ts
index f613f2800..7be9211a4 100644
--- a/cli/dts/lib.deno.worker.d.ts
+++ b/cli/dts/lib.deno.worker.d.ts
@@ -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,
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index d477bb896..25d84ae46 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -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",
});
diff --git a/cli/tests/testdata/unhandled_rejection.js b/cli/tests/testdata/unhandled_rejection.ts
index 352e861b4..388583434 100644
--- a/cli/tests/testdata/unhandled_rejection.js
+++ b/cli/tests/testdata/unhandled_rejection.ts
@@ -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();
diff --git a/cli/tests/testdata/unhandled_rejection.js.out b/cli/tests/testdata/unhandled_rejection.ts.out
index 4c41795ce..6addab20a 100644
--- a/cli/tests/testdata/unhandled_rejection.js.out
+++ b/cli/tests/testdata/unhandled_rejection.ts.out
@@ -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