oven-sh / bun

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

bun-types websocket type incorrect #8214

Open danthegoodman1 opened 8 months ago

danthegoodman1 commented 8 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 8 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.