1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/ext/broadcast_channel/lib.deno_broadcast_channel.d.ts
ud2 d632cce129
fix(dts): make globals available on globalThis (#19438)
This PR changes Web IDL interfaces to be declared with `var` instead of
`class`, so that accessing them via `globalThis` does not raise type
errors.

Closes #13390.
2023-07-03 14:36:55 -04:00

58 lines
1.8 KiB
TypeScript

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-explicit-any no-var
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
/** @category Broadcast Channel */
declare interface BroadcastChannelEventMap {
"message": MessageEvent;
"messageerror": MessageEvent;
}
/** @category Broadcast Channel */
declare interface BroadcastChannel extends EventTarget {
/**
* Returns the channel name (as passed to the constructor).
*/
readonly name: string;
onmessage: ((this: BroadcastChannel, ev: MessageEvent) => any) | null;
onmessageerror: ((this: BroadcastChannel, ev: MessageEvent) => any) | null;
/**
* Closes the BroadcastChannel object, opening it up to garbage collection.
*/
close(): void;
/**
* Sends the given message to other BroadcastChannel objects set up for
* this channel. Messages can be structured objects, e.g. nested objects
* and arrays.
*/
postMessage(message: any): void;
addEventListener<K extends keyof BroadcastChannelEventMap>(
type: K,
listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof BroadcastChannelEventMap>(
type: K,
listener: (this: BroadcastChannel, ev: BroadcastChannelEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}
/** @category Broadcast Channel */
declare var BroadcastChannel: {
readonly prototype: BroadcastChannel;
new (name: string): BroadcastChannel;
};