diff options
Diffstat (limited to 'ws/mod.ts')
| -rw-r--r-- | ws/mod.ts | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -31,19 +31,25 @@ export interface WebSocketCloseEvent { reason?: string; } -export function isWebSocketCloseEvent(a): a is WebSocketCloseEvent { - return a && typeof a["code"] === "number"; +export function isWebSocketCloseEvent( + a: WebSocketEvent +): a is WebSocketCloseEvent { + return typeof a === "object" && a.hasOwnProperty("code"); } export type WebSocketPingEvent = ["ping", Uint8Array]; -export function isWebSocketPingEvent(a): a is WebSocketPingEvent { +export function isWebSocketPingEvent( + a: WebSocketEvent +): a is WebSocketPingEvent { return Array.isArray(a) && a[0] === "ping" && a[1] instanceof Uint8Array; } export type WebSocketPongEvent = ["pong", Uint8Array]; -export function isWebSocketPongEvent(a): a is WebSocketPongEvent { +export function isWebSocketPongEvent( + a: WebSocketEvent +): a is WebSocketPongEvent { return Array.isArray(a) && a[0] === "pong" && a[1] instanceof Uint8Array; } @@ -436,6 +442,8 @@ async function handshake( if (!m) { throw new Error("ws: invalid status line: " + statusLine); } + + // @ts-ignore const { version, statusCode } = m.groups; if (version !== "HTTP/1.1" || statusCode !== "101") { throw new Error( |
