mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
fix: update worker types to better align to lib.dom.d.ts (#7843)
This commit is contained in:
parent
986ad08bce
commit
9d71b0ef5b
5 changed files with 69 additions and 29 deletions
15
cli/dts/lib.deno.shared_globals.d.ts
vendored
15
cli/dts/lib.deno.shared_globals.d.ts
vendored
|
@ -606,15 +606,20 @@ declare class URL {
|
|||
toJSON(): string;
|
||||
}
|
||||
|
||||
interface MessageEventInit extends EventInit {
|
||||
data?: any;
|
||||
interface MessageEventInit<T = any> extends EventInit {
|
||||
data?: T;
|
||||
origin?: string;
|
||||
lastEventId?: string;
|
||||
}
|
||||
|
||||
declare class MessageEvent extends Event {
|
||||
readonly data: any;
|
||||
readonly origin: string;
|
||||
declare class MessageEvent<T = any> extends Event {
|
||||
/**
|
||||
* Returns the data of the message.
|
||||
*/
|
||||
readonly data: T;
|
||||
/**
|
||||
* Returns the last event ID string, for server-sent events.
|
||||
*/
|
||||
readonly lastEventId: string;
|
||||
constructor(type: string, eventInitDict?: MessageEventInit);
|
||||
}
|
||||
|
|
64
cli/dts/lib.deno.worker.d.ts
vendored
64
cli/dts/lib.deno.worker.d.ts
vendored
|
@ -9,35 +9,51 @@
|
|||
|
||||
declare interface DedicatedWorkerGlobalScope {
|
||||
self: DedicatedWorkerGlobalScope & typeof globalThis;
|
||||
onmessage: (e: MessageEvent) => void;
|
||||
onmessageerror: (e: MessageEvent) => void;
|
||||
onerror: undefined | typeof onerror;
|
||||
name: typeof __workerMain.name;
|
||||
close: typeof __workerMain.close;
|
||||
postMessage: typeof __workerMain.postMessage;
|
||||
onmessage:
|
||||
| ((
|
||||
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||
ev: MessageEvent,
|
||||
) => any)
|
||||
| null;
|
||||
onmessageerror:
|
||||
| ((
|
||||
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||
ev: MessageEvent,
|
||||
) => any)
|
||||
| null;
|
||||
onerror:
|
||||
| ((
|
||||
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||
ev: ErrorEvent,
|
||||
) => any)
|
||||
| null;
|
||||
name: string;
|
||||
close: () => void;
|
||||
postMessage: (message: any) => void;
|
||||
Deno: typeof Deno;
|
||||
}
|
||||
|
||||
declare var self: DedicatedWorkerGlobalScope & typeof globalThis;
|
||||
declare var onmessage: ((e: { data: any }) => Promise<void> | void) | undefined;
|
||||
declare var onmessage:
|
||||
| ((
|
||||
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||
ev: MessageEvent,
|
||||
) => any)
|
||||
| null;
|
||||
declare var onmessageerror:
|
||||
| ((
|
||||
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||
ev: MessageEvent,
|
||||
) => any)
|
||||
| null;
|
||||
declare var onerror:
|
||||
| ((
|
||||
msg: string,
|
||||
source: string,
|
||||
lineno: number,
|
||||
colno: number,
|
||||
e: Event,
|
||||
) => boolean | void)
|
||||
| undefined;
|
||||
declare var close: typeof __workerMain.close;
|
||||
declare var name: typeof __workerMain.name;
|
||||
declare var postMessage: typeof __workerMain.postMessage;
|
||||
|
||||
declare namespace __workerMain {
|
||||
export let onmessage: (e: { data: any }) => void;
|
||||
export function postMessage(data: any): void;
|
||||
export function close(): void;
|
||||
export const name: string;
|
||||
}
|
||||
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||
ev: ErrorEvent,
|
||||
) => any)
|
||||
| null;
|
||||
declare var close: () => void;
|
||||
declare var name: string;
|
||||
declare var postMessage: (message: any) => void;
|
||||
|
||||
/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */
|
||||
|
|
4
cli/tests/subdir/worker_types.ts
Normal file
4
cli/tests/subdir/worker_types.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
// eslint-disable-next-line require-await
|
||||
self.onmessage = async (_msg: MessageEvent) => {
|
||||
self.postMessage("hello");
|
||||
};
|
|
@ -74,6 +74,7 @@ import "./umask_test.ts";
|
|||
import "./url_test.ts";
|
||||
import "./url_search_params_test.ts";
|
||||
import "./utime_test.ts";
|
||||
import "./worker_types.ts";
|
||||
import "./write_file_test.ts";
|
||||
import "./write_text_file_test.ts";
|
||||
import "./performance_test.ts";
|
||||
|
|
14
cli/tests/unit/worker_types.ts
Normal file
14
cli/tests/unit/worker_types.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert, unitTest } from "./test_util.ts";
|
||||
|
||||
unitTest(
|
||||
{ perms: { read: true } },
|
||||
function utimeSyncFileSuccess() {
|
||||
const w = new Worker(
|
||||
new URL("../subdir/worker_types.ts", import.meta.url).href,
|
||||
{ type: "module" },
|
||||
);
|
||||
assert(w);
|
||||
w.terminate();
|
||||
},
|
||||
);
|
Loading…
Reference in a new issue