fix: add EventSource typings (#21908)

Fixes #21691
This commit is contained in:
Leo Kettmeir 2024-01-12 14:28:54 +01:00 committed by GitHub
parent f45ceb2320
commit 4122c8f164
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -405,3 +405,88 @@ declare function fetch(
input: URL | Request | string,
init?: RequestInit,
): Promise<Response>;
/**
* @category Fetch API
*/
declare interface EventSourceInit {
withCredentials?: boolean;
}
/**
* @category Fetch API
*/
declare interface EventSourceEventMap {
"error": Event;
"message": MessageEvent;
"open": Event;
}
/**
* @category Fetch API
*/
declare interface EventSource extends EventTarget {
onerror: ((this: EventSource, ev: Event) => any) | null;
onmessage: ((this: EventSource, ev: MessageEvent) => any) | null;
onopen: ((this: EventSource, ev: Event) => any) | null;
/**
* Returns the state of this EventSource object's connection. It can have the values described below.
*/
readonly readyState: number;
/**
* Returns the URL providing the event stream.
*/
readonly url: string;
/**
* Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
*/
readonly withCredentials: boolean;
/**
* Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
*/
close(): void;
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSED: 2;
addEventListener<K extends keyof EventSourceEventMap>(
type: K,
listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: (this: EventSource, event: MessageEvent) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof EventSourceEventMap>(
type: K,
listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: (this: EventSource, event: MessageEvent) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}
/**
* @category Fetch API
*/
declare var EventSource: {
prototype: EventSource;
new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource;
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSED: 2;
};