diff --git a/test/types/event-source-d.ts b/test/types/event-source-d.ts new file mode 100644 index 00000000000..58cfa9364e8 --- /dev/null +++ b/test/types/event-source-d.ts @@ -0,0 +1,20 @@ +import { URL } from 'url' +import { expectType } from 'tsd' + +import { + EventSource, +} from '../../' + +declare const eventSource: EventSource + +expectType<() => void>(eventSource.close) +expectType(eventSource.url) +expectType(eventSource.withCredentials) +expectType<0 | 1 | 2>(eventSource.readyState) + +expectType(new EventSource('https://example.com')) +expectType(new EventSource(new URL('https://example.com'))) +expectType(new EventSource('https://example.com', {})) +expectType(new EventSource('https://example.com', { + withCredentials: true, +})) diff --git a/types/eventsource.d.ts b/types/eventsource.d.ts index 0615bf45e90..af8b92e626c 100644 --- a/types/eventsource.d.ts +++ b/types/eventsource.d.ts @@ -50,7 +50,7 @@ interface EventSource extends EventTarget { export declare const EventSource: { prototype: EventSource - new (url: string | URL, init: EventSourceInit): EventSource + new (url: string | URL, init?: EventSourceInit): EventSource readonly CLOSED: 2 readonly CONNECTING: 0 readonly OPEN: 1