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:
parent
f43855cead
commit
b12afdb89a
2 changed files with 85 additions and 82 deletions
18
cli/dts/lib.deno.shared_globals.d.ts
vendored
18
cli/dts/lib.deno.shared_globals.d.ts
vendored
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue