1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 15:19:40 -05:00

feat: Add WorkerOptions interface to type declarations (#9147)

This commit is contained in:
Nayeem Rahman 2021-01-19 02:26:39 +00:00 committed by GitHub
parent f43855cead
commit b12afdb89a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 82 deletions

View file

@ -653,13 +653,7 @@ interface WorkerEventMap extends AbstractWorkerEventMap {
"messageerror": MessageEvent;
}
declare class Worker extends EventTarget {
onerror?: (e: ErrorEvent) => void;
onmessage?: (e: MessageEvent) => void;
onmessageerror?: (e: MessageEvent) => void;
constructor(
specifier: string,
options?: {
interface WorkerOptions {
type?: "classic" | "module";
name?: string;
/** UNSTABLE: New API.
@ -739,7 +733,15 @@ declare class Worker extends EventTarget {
write?: "inherit" | boolean | Array<string | URL>;
};
};
},
}
declare class Worker extends EventTarget {
onerror?: (e: ErrorEvent) => void;
onmessage?: (e: MessageEvent) => void;
onmessageerror?: (e: MessageEvent) => void;
constructor(
specifier: string,
options?: WorkerOptions,
);
postMessage(message: any, transfer: ArrayBuffer[]): void;
postMessage(message: any, options?: PostMessageOptions): void;

View file

@ -113,9 +113,10 @@ Deno.test({
name: "worker globals",
fn: async function (): Promise<void> {
const promise = deferred();
const workerOptions: WorkerOptions = { type: "module" };
const w = new Worker(
new URL("workers/worker_globals.ts", import.meta.url).href,
{ type: "module" },
workerOptions,
);
w.onmessage = (e): void => {
assertEquals(e.data, "true, true, true");