Skip to content

Add HTML Web workers types #804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10898,6 +10898,7 @@ interface Navigator extends MSFileSaver, MSNavigatorDoNotTrack, NavigatorAutomat
getVRDisplays(): Promise<VRDisplay[]>;
msLaunchUri(uri: string, successCallback?: MSLaunchUriCallback, noHandlerCallback?: MSLaunchUriCallback): void;
requestMediaKeySystemAccess(keySystem: string, supportedConfigurations: MediaKeySystemConfiguration[]): Promise<MediaKeySystemAccess>;
sendBeacon(url: string, data?: BodyInit | null): boolean;
vibrate(pattern: number | number[]): boolean;
}

Expand Down Expand Up @@ -15169,6 +15170,22 @@ declare var ShadowRoot: {
new(): ShadowRoot;
};

interface SharedWorker extends EventTarget, AbstractWorker {
/**
* Returns sharedWorker's MessagePort object which can be used to communicate with the global environment.
*/
readonly port: MessagePort;
addEventListener<K extends keyof AbstractWorkerEventMap>(type: K, listener: (this: SharedWorker, ev: AbstractWorkerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof AbstractWorkerEventMap>(type: K, listener: (this: SharedWorker, ev: AbstractWorkerEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

declare var SharedWorker: {
prototype: SharedWorker;
new(scriptURL: string, options?: string | WorkerOptions): SharedWorker;
};

interface Slotable {
readonly assignedSlot: HTMLSlotElement | null;
}
Expand Down Expand Up @@ -18582,7 +18599,6 @@ interface Window extends EventTarget, AnimationFrameProvider, GlobalEventHandler
readonly history: History;
readonly innerHeight: number;
readonly innerWidth: number;
readonly isSecureContext: boolean;
readonly length: number;
location: Location;
readonly locationbar: BarProp;
Expand Down Expand Up @@ -18749,6 +18765,7 @@ interface WindowOrWorkerGlobalScope {
readonly caches: CacheStorage;
readonly crypto: Crypto;
readonly indexedDB: IDBFactory;
readonly isSecureContext: boolean;
readonly origin: string;
readonly performance: Performance;
atob(data: string): string;
Expand All @@ -18769,13 +18786,21 @@ interface WindowSessionStorage {

interface WorkerEventMap extends AbstractWorkerEventMap {
"message": MessageEvent;
"messageerror": MessageEvent;
}

/** This Web Workers API interface represents a background task that can be easily created and can send messages back to its creator. Creating a worker is as simple as calling the Worker() constructor and specifying a script to be run in the worker thread. */
interface Worker extends EventTarget, AbstractWorker {
onmessage: ((this: Worker, ev: MessageEvent) => any) | null;
onmessageerror: ((this: Worker, ev: MessageEvent) => any) | null;
/**
* Clones message and transmits it to worker's global environment. transfer can be passed as a list of objects that are to be transferred rather than cloned.
*/
postMessage(message: any, transfer: Transferable[]): void;
postMessage(message: any, options?: PostMessageOptions): void;
/**
* Aborts worker's associated global environment.
*/
terminate(): void;
addEventListener<K extends keyof WorkerEventMap>(type: K, listener: (this: Worker, ev: WorkerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
Expand Down Expand Up @@ -19572,7 +19597,6 @@ declare var frames: Window;
declare var history: History;
declare var innerHeight: number;
declare var innerWidth: number;
declare var isSecureContext: boolean;
declare var length: number;
declare var location: Location;
declare var locationbar: BarProp;
Expand Down Expand Up @@ -19951,6 +19975,7 @@ declare function requestAnimationFrame(callback: FrameRequestCallback): number;
declare var caches: CacheStorage;
declare var crypto: Crypto;
declare var indexedDB: IDBFactory;
declare var isSecureContext: boolean;
declare var origin: string;
declare var performance: Performance;
declare function atob(data: string): string;
Expand Down
161 changes: 124 additions & 37 deletions baselines/webworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1264,12 +1264,24 @@ declare var DOMStringList: {

interface DedicatedWorkerGlobalScopeEventMap extends WorkerGlobalScopeEventMap {
"message": MessageEvent;
"messageerror": MessageEvent;
}

/** (the Worker global scope) is accessible through the self keyword. Some additional global functions, namespaces objects, and constructors, not typically associated with the worker global scope, but available on it, are listed in the JavaScript Reference. See also: Functions available to workers. */
interface DedicatedWorkerGlobalScope extends WorkerGlobalScope, AnimationFrameProvider {
/**
* Returns dedicatedWorkerGlobal's name, i.e. the value given to the Worker constructor. Primarily useful for debugging.
*/
readonly name: string;
onmessage: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null;
onmessageerror: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null;
/**
* Aborts dedicatedWorkerGlobal.
*/
close(): void;
/**
* Clones message and transmits it to the Worker object associated with dedicatedWorkerGlobal. transfer can be passed as a list of objects that are to be transferred rather than cloned.
*/
postMessage(message: any, transfer: Transferable[]): void;
postMessage(message: any, options?: PostMessageOptions): void;
addEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
Expand Down Expand Up @@ -2318,10 +2330,6 @@ declare var NavigationPreloadManager: {
new(): NavigationPreloadManager;
};

interface NavigatorBeacon {
sendBeacon(url: string, data?: Blob | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer | FormData | string | null): boolean;
}

interface NavigatorConcurrentHardware {
readonly hardwareConcurrency: number;
}
Expand All @@ -2335,6 +2343,11 @@ interface NavigatorID {
readonly userAgent: string;
}

interface NavigatorLanguage {
readonly language: string;
readonly languages: ReadonlyArray<string>;
}

interface NavigatorOnLine {
readonly onLine: boolean;
}
Expand Down Expand Up @@ -3001,6 +3014,47 @@ declare var ServiceWorkerRegistration: {
new(): ServiceWorkerRegistration;
};

interface SharedWorker extends EventTarget, AbstractWorker {
/**
* Returns sharedWorker's MessagePort object which can be used to communicate with the global environment.
*/
readonly port: MessagePort;
addEventListener<K extends keyof AbstractWorkerEventMap>(type: K, listener: (this: SharedWorker, ev: AbstractWorkerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof AbstractWorkerEventMap>(type: K, listener: (this: SharedWorker, ev: AbstractWorkerEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

declare var SharedWorker: {
prototype: SharedWorker;
new(scriptURL: string, options?: string | WorkerOptions): SharedWorker;
};

interface SharedWorkerGlobalScopeEventMap extends WorkerGlobalScopeEventMap {
"connect": MessageEvent;
}

interface SharedWorkerGlobalScope extends WorkerGlobalScope {
/**
* Returns sharedWorkerGlobal's name, i.e. the value given to the SharedWorker constructor. Multiple SharedWorker objects can correspond to the same shared worker (and SharedWorkerGlobalScope), by reusing the same name.
*/
readonly name: string;
onconnect: ((this: SharedWorkerGlobalScope, ev: MessageEvent) => any) | null;
/**
* Aborts sharedWorkerGlobal.
*/
close(): void;
addEventListener<K extends keyof SharedWorkerGlobalScopeEventMap>(type: K, listener: (this: SharedWorkerGlobalScope, ev: SharedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof SharedWorkerGlobalScopeEventMap>(type: K, listener: (this: SharedWorkerGlobalScope, ev: SharedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

declare var SharedWorkerGlobalScope: {
prototype: SharedWorkerGlobalScope;
new(): SharedWorkerGlobalScope;
};

interface StorageManager {
estimate(): Promise<StorageEstimate>;
persisted(): Promise<boolean>;
Expand Down Expand Up @@ -5342,11 +5396,6 @@ declare var WebSocket: {
readonly OPEN: number;
};

interface WindowBase64 {
atob(encodedString: string): string;
btoa(rawString: string): string;
}

/** This ServiceWorker API interface represents the scope of a service worker client that is a document in a browser context, controlled by an active worker. The service worker client independently selects and uses a service worker for its own loading and sub-resources. */
interface WindowClient extends Client {
readonly ancestorOrigins: ReadonlyArray<string>;
Expand All @@ -5369,6 +5418,7 @@ interface WindowOrWorkerGlobalScope {
readonly caches: CacheStorage;
readonly crypto: Crypto;
readonly indexedDB: IDBFactory;
readonly isSecureContext: boolean;
readonly origin: string;
readonly performance: Performance;
atob(data: string): string;
Expand All @@ -5385,13 +5435,21 @@ interface WindowOrWorkerGlobalScope {

interface WorkerEventMap extends AbstractWorkerEventMap {
"message": MessageEvent;
"messageerror": MessageEvent;
}

/** This Web Workers API interface represents a background task that can be easily created and can send messages back to its creator. Creating a worker is as simple as calling the Worker() constructor and specifying a script to be run in the worker thread. */
interface Worker extends EventTarget, AbstractWorker {
onmessage: ((this: Worker, ev: MessageEvent) => any) | null;
onmessageerror: ((this: Worker, ev: MessageEvent) => any) | null;
/**
* Clones message and transmits it to worker's global environment. transfer can be passed as a list of objects that are to be transferred rather than cloned.
*/
postMessage(message: any, transfer: Transferable[]): void;
postMessage(message: any, options?: PostMessageOptions): void;
/**
* Aborts worker's associated global environment.
*/
terminate(): void;
addEventListener<K extends keyof WorkerEventMap>(type: K, listener: (this: Worker, ev: WorkerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
Expand All @@ -5406,17 +5464,34 @@ declare var Worker: {

interface WorkerGlobalScopeEventMap {
"error": ErrorEvent;
"languagechange": Event;
"offline": Event;
"online": Event;
"rejectionhandled": PromiseRejectionEvent;
"unhandledrejection": PromiseRejectionEvent;
}

/** This Web Workers API interface is an interface representing the scope of any worker. Workers have no browsing context; this scope contains the information usually conveyed by Window objects — in this case event handlers, the console or the associated WorkerNavigator object. Each WorkerGlobalScope has its own event loop. */
interface WorkerGlobalScope extends EventTarget, WindowConsole, WindowOrWorkerGlobalScope, WorkerUtils {
readonly caches: CacheStorage;
readonly isSecureContext: boolean;
interface WorkerGlobalScope extends EventTarget, WindowConsole, WindowOrWorkerGlobalScope {
/**
* Returns workerGlobal's WorkerLocation object.
*/
readonly location: WorkerLocation;
readonly navigator: WorkerNavigator;
onerror: ((this: WorkerGlobalScope, ev: ErrorEvent) => any) | null;
readonly performance: Performance;
onlanguagechange: ((this: WorkerGlobalScope, ev: Event) => any) | null;
onoffline: ((this: WorkerGlobalScope, ev: Event) => any) | null;
ononline: ((this: WorkerGlobalScope, ev: Event) => any) | null;
onrejectionhandled: ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any) | null;
onunhandledrejection: ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any) | null;
/**
* Returns workerGlobal.
*/
readonly self: WorkerGlobalScope & typeof globalThis;
msWriteProfilerMark(profilerMarkName: string): void;
/**
* Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss).
*/
importScripts(...urls: string[]): void;
addEventListener<K extends keyof WorkerGlobalScopeEventMap>(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof WorkerGlobalScopeEventMap>(type: K, listener: (this: WorkerGlobalScope, ev: WorkerGlobalScopeEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -5448,7 +5523,7 @@ declare var WorkerLocation: {
};

/** A subset of the Navigator interface allowed to be accessed from a Worker. Such an object is initialized for each worker and is available via the WorkerGlobalScope.navigator property obtained by calling window.self.navigator. */
interface WorkerNavigator extends NavigatorBeacon, NavigatorConcurrentHardware, NavigatorID, NavigatorOnLine, NavigatorStorage {
interface WorkerNavigator extends NavigatorConcurrentHardware, NavigatorID, NavigatorLanguage, NavigatorOnLine, NavigatorStorage {
readonly permissions: Permissions;
readonly serviceWorker: ServiceWorkerContainer;
}
Expand All @@ -5458,13 +5533,6 @@ declare var WorkerNavigator: {
new(): WorkerNavigator;
};

interface WorkerUtils extends WindowBase64 {
readonly indexedDB: IDBFactory;
readonly msIndexedDB: IDBFactory;
readonly navigator: WorkerNavigator;
importScripts(...urls: string[]): void;
}

/** This Streams API interface provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in backpressure and queuing. */
interface WritableStream<W = any> {
readonly locked: boolean;
Expand Down Expand Up @@ -5747,14 +5815,14 @@ declare namespace WebAssembly {
function validate(bytes: BufferSource): boolean;
}

interface EventHandlerNonNull {
(event: Event): any;
}

interface FrameRequestCallback {
(time: number): void;
}

interface OnErrorEventHandlerNonNull {
(event: Event | string, source?: string, lineno?: number, colno?: number, error?: Error): any;
}

interface PerformanceObserverCallback {
(entries: PerformanceObserverEntryList, observer: PerformanceObserver): void;
}
Expand Down Expand Up @@ -5803,35 +5871,52 @@ interface WritableStreamErrorCallback {
(reason: any): void | PromiseLike<void>;
}

/**
* Returns dedicatedWorkerGlobal's name, i.e. the value given to the Worker constructor. Primarily useful for debugging.
*/
declare var name: string;
declare var onmessage: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null;
declare var onmessageerror: ((this: DedicatedWorkerGlobalScope, ev: MessageEvent) => any) | null;
/**
* Aborts dedicatedWorkerGlobal.
*/
declare function close(): void;
/**
* Clones message and transmits it to the Worker object associated with dedicatedWorkerGlobal. transfer can be passed as a list of objects that are to be transferred rather than cloned.
*/
declare function postMessage(message: any, transfer: Transferable[]): void;
declare function postMessage(message: any, options?: PostMessageOptions): void;
/**
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
*/
declare function dispatchEvent(event: Event): boolean;
declare var caches: CacheStorage;
declare var isSecureContext: boolean;
/**
* Returns workerGlobal's WorkerLocation object.
*/
declare var location: WorkerLocation;
declare var navigator: WorkerNavigator;
declare var onerror: ((this: DedicatedWorkerGlobalScope, ev: ErrorEvent) => any) | null;
declare var performance: Performance;
declare var onlanguagechange: ((this: DedicatedWorkerGlobalScope, ev: Event) => any) | null;
declare var onoffline: ((this: DedicatedWorkerGlobalScope, ev: Event) => any) | null;
declare var ononline: ((this: DedicatedWorkerGlobalScope, ev: Event) => any) | null;
declare var onrejectionhandled: ((this: DedicatedWorkerGlobalScope, ev: PromiseRejectionEvent) => any) | null;
declare var onunhandledrejection: ((this: DedicatedWorkerGlobalScope, ev: PromiseRejectionEvent) => any) | null;
/**
* Returns workerGlobal.
*/
declare var self: WorkerGlobalScope & typeof globalThis;
declare function msWriteProfilerMark(profilerMarkName: string): void;
/**
* Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss).
*/
declare function importScripts(...urls: string[]): void;
/**
* Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.
*/
declare function dispatchEvent(event: Event): boolean;
declare var indexedDB: IDBFactory;
declare var msIndexedDB: IDBFactory;
declare var navigator: WorkerNavigator;
declare function importScripts(...urls: string[]): void;
declare function atob(encodedString: string): string;
declare function btoa(rawString: string): string;
declare var console: Console;
declare var caches: CacheStorage;
declare var crypto: Crypto;
declare var indexedDB: IDBFactory;
declare var isSecureContext: boolean;
declare var origin: string;
declare var performance: Performance;
declare function atob(data: string): string;
Expand All @@ -5844,6 +5929,7 @@ declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response
declare function queueMicrotask(callback: VoidFunction): void;
declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
declare var console: Console;
declare function cancelAnimationFrame(handle: number): void;
declare function requestAnimationFrame(callback: FrameRequestCallback): number;
declare function addEventListener<K extends keyof DedicatedWorkerGlobalScopeEventMap>(type: K, listener: (this: DedicatedWorkerGlobalScope, ev: DedicatedWorkerGlobalScopeEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
Expand All @@ -5859,6 +5945,7 @@ type CanvasImageSource = ImageBitmap | OffscreenCanvas;
type OffscreenRenderingContext = OffscreenCanvasRenderingContext2D | ImageBitmapRenderingContext | WebGLRenderingContext | WebGL2RenderingContext;
type MessageEventSource = MessagePort | ServiceWorker;
type ImageBitmapSource = CanvasImageSource | Blob | ImageData;
type OnErrorEventHandler = OnErrorEventHandlerNonNull | null;
type TimerHandler = string | Function;
type PerformanceEntryList = PerformanceEntry[];
type PushMessageDataInit = BufferSource | string;
Expand Down
Loading