1
0
Fork 0
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:
Kitson Kelly 2020-10-08 20:43:26 +11:00 committed by GitHub
parent 986ad08bce
commit 9d71b0ef5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 29 deletions

View file

@ -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);
}

View file

@ -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 */

View file

@ -0,0 +1,4 @@
// eslint-disable-next-line require-await
self.onmessage = async (_msg: MessageEvent) => {
self.postMessage("hello");
};

View file

@ -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";

View 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();
},
);