Skip to content

Commit

Permalink
fix(types): The second parameter of EventSource is optional (#3106)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbinlin committed Apr 13, 2024
1 parent 8f192e3 commit 7a94682
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/types/event-source-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { URL } from 'url'
import { expectType } from 'tsd'

import {
EventSource,
} from '../../'

declare const eventSource: EventSource

expectType<() => void>(eventSource.close)
expectType<string>(eventSource.url)
expectType<boolean>(eventSource.withCredentials)
expectType<0 | 1 | 2>(eventSource.readyState)

expectType<EventSource>(new EventSource('https://example.com'))
expectType<EventSource>(new EventSource(new URL('https://example.com')))
expectType<EventSource>(new EventSource('https://example.com', {}))
expectType<EventSource>(new EventSource('https://example.com', {
withCredentials: true,
}))
2 changes: 1 addition & 1 deletion types/eventsource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7a94682

Please sign in to comment.