Skip to content

Commit

Permalink
fix: add EventSource typings (#21908)
Browse files Browse the repository at this point in the history
Fixes #21691
  • Loading branch information
crowlKats authored and bartlomieju committed Jan 12, 2024
1 parent a7c46a5 commit 991adb7
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions ext/fetch/lib.deno_fetch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 991adb7

Please sign in to comment.