ryo-ma / deno-websocket

🦕 A simple WebSocket library like ws of node.js library for deno
https://deno.land/x/websocket
MIT License
152 stars 17 forks source link

Support stricter type for Deno 1.4 #10

Closed bebraw closed 3 years ago

bebraw commented 3 years ago

It looks like Deno 1.4 is stricter with typing.

The fix is to change WebSocket to be exported as a type at https://github.com/ryo-ma/deno-websocket/blob/master/deps.ts .

export type {
  WebSocket,
} from "https://deno.land/std@0.65.0/ws/mod.ts";

More specifically, it looks like the issue originates from https://deno.land/posts/v1.4#stricter-type-checks-in-code--unstablecode (--unstable flag).

ryo-ma commented 3 years ago

I will consider supporting Deno 1.4. But I think deno-websocket is losing its existence value due to WebSocket API. https://deno.land/posts/v1.4#websocket-api

Do you need this library?

bebraw commented 3 years ago

If I'm interpreting right, that's only the client portion. Please correct me if I'm wrong. 😄

ryo-ma commented 3 years ago

I see! It may be exactly what you say. I will check in detail later.

bebraw commented 3 years ago

Cool, it looks like the fix is simple. To be future-compatible, all we have to do is to change the export.

ryo-ma commented 3 years ago

Released v0.0.4. Please confirm it. Then I will update std lib later.

bebraw commented 3 years ago

It looks like the current fix fails with

TS1362 [ERROR]: 'WebSocketServer' cannot be used as a value because it was exported using 'export type'.
  const wss = new WebSocketServer(8080);

In my local branch, changing deps.ts to

export { EventEmitter } from "https://deno.land/std@0.65.0/node/events.ts";
export { Server, serve } from "https://deno.land/std@0.65.0/http/server.ts";
export {
  acceptWebSocket,
  isWebSocketCloseEvent,
  isWebSocketPingEvent,
  isWebSocketPongEvent,
  connectWebSocket,
} from "https://deno.land/std@0.65.0/ws/mod.ts";
export type {
  WebSocket,
} from "https://deno.land/std@0.65.0/ws/mod.ts";

was enough given WebSocket is the only type we expose as far as I understand.

ryo-ma commented 3 years ago

I made a mistake. I have fixed it. And I have released v0.0.5.

bebraw commented 3 years ago

Great, looks like that one works well. Thanks for the fix. 👍