pladaria / reconnecting-websocket

Reconnecting WebSocket. For Web, React Native, cli (Node.js)
MIT License
1.22k stars 197 forks source link

Event type mismatch using addEventListener and onerror #104

Closed andsouto closed 5 years ago

andsouto commented 5 years ago

When using the addEventListener/removeEventListener methods to listen for error events, the event parameter is expected to be of type ErrorEvent. See https://github.com/pladaria/reconnecting-websocket/blob/master/events.ts#L37

export interface WebSocketEventListenerMap {
    close: (event: CloseEvent) => void | {handleEvent: (event: CloseEvent) => void};
    error: (event: ErrorEvent) => void | {handleEvent: (event: ErrorEvent) => void};
    message: (event: MessageEvent) => void | {handleEvent: (event: MessageEvent) => void};
    open: (event: Event) => void | {handleEvent: (event: Event) => void};
}

However, when using the .onerror property the event is expected to be of type Event. See https://github.com/pladaria/reconnecting-websocket/blob/master/reconnecting-websocket.ts#L194

public onerror?: (event: Event) => void = undefined;
pladaria commented 5 years ago

Thanks for reporting, next version will fix it