oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.48k stars 2.78k forks source link

bun-types websocket type incorrect #8214

Open danthegoodman1 opened 10 months ago

danthegoodman1 commented 10 months ago

What version of Bun is running?

1.0.21+837cbd60d

What platform is your computer?

maxos x86

What steps can reproduce the bug?

The second parameter of websocket initialization does not reflect the docs, and if I add a // @ts-expect-error it works fine.

const dgWS = new WebSocket("wss://api.deepgram.com/v1/listen", {
    headers: {
      "Authorization": `Bearer ${process.env.DEEPGRAM_KEY}`
    }
  })
image

What is the expected behavior?

https://bun.sh/docs/api/websockets#connect-to-a-websocket-server

What do you see instead?

No response

Additional information

import WebSocket from "ws"

is a temporary workaround

thecrabcode commented 10 months ago

We are also experiencing this issue, if we use new WebSocket() then we get

This expression is not constructable.
  Type 'typeof import("/PATH/TO/REPO/node_modules/@types/ws/index")' has no construct signatures.
nektro commented 1 month ago

is this still affecting you in Bun 1.1.31? i get the following:

import WebSocket from "ws";

const dgWS = new WebSocket("wss://api.deepgram.com/v1/listen", {
  headers: {
    "Authorization": `Bearer ${process.env.DEEPGRAM_KEY}`,
  },
});

Image