mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00: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;
|
toJSON(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MessageEventInit extends EventInit {
|
interface MessageEventInit<T = any> extends EventInit {
|
||||||
data?: any;
|
data?: T;
|
||||||
origin?: string;
|
origin?: string;
|
||||||
lastEventId?: string;
|
lastEventId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare class MessageEvent extends Event {
|
declare class MessageEvent<T = any> extends Event {
|
||||||
readonly data: any;
|
/**
|
||||||
readonly origin: string;
|
* Returns the data of the message.
|
||||||
|
*/
|
||||||
|
readonly data: T;
|
||||||
|
/**
|
||||||
|
* Returns the last event ID string, for server-sent events.
|
||||||
|
*/
|
||||||
readonly lastEventId: string;
|
readonly lastEventId: string;
|
||||||
constructor(type: string, eventInitDict?: MessageEventInit);
|
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 {
|
declare interface DedicatedWorkerGlobalScope {
|
||||||
self: DedicatedWorkerGlobalScope & typeof globalThis;
|
self: DedicatedWorkerGlobalScope & typeof globalThis;
|
||||||
onmessage: (e: MessageEvent) => void;
|
onmessage:
|
||||||
onmessageerror: (e: MessageEvent) => void;
|
| ((
|
||||||
onerror: undefined | typeof onerror;
|
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||||
name: typeof __workerMain.name;
|
ev: MessageEvent,
|
||||||
close: typeof __workerMain.close;
|
) => any)
|
||||||
postMessage: typeof __workerMain.postMessage;
|
| 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;
|
Deno: typeof Deno;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare var self: DedicatedWorkerGlobalScope & typeof globalThis;
|
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:
|
declare var onerror:
|
||||||
| ((
|
| ((
|
||||||
msg: string,
|
this: DedicatedWorkerGlobalScope & typeof globalThis,
|
||||||
source: string,
|
ev: ErrorEvent,
|
||||||
lineno: number,
|
) => any)
|
||||||
colno: number,
|
| null;
|
||||||
e: Event,
|
declare var close: () => void;
|
||||||
) => boolean | void)
|
declare var name: string;
|
||||||
| undefined;
|
declare var postMessage: (message: any) => void;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* eslint-enable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any */
|
/* 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_test.ts";
|
||||||
import "./url_search_params_test.ts";
|
import "./url_search_params_test.ts";
|
||||||
import "./utime_test.ts";
|
import "./utime_test.ts";
|
||||||
|
import "./worker_types.ts";
|
||||||
import "./write_file_test.ts";
|
import "./write_file_test.ts";
|
||||||
import "./write_text_file_test.ts";
|
import "./write_text_file_test.ts";
|
||||||
import "./performance_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…
Add table
Add a link
Reference in a new issue