Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types for the WebSocket global include methods that don't exist at runtime #15883

Open
lilnasy opened this issue Dec 19, 2024 · 0 comments
Open
Labels
bug Something isn't working types An issue with TypeScript types

Comments

@lilnasy
Copy link

lilnasy commented Dec 19, 2024

What version of Bun is running?

1.1.40+b5b51004e

What platform is your computer?

Linux 6.1.91-060191-generic x86_64 unknown

What steps can reproduce the bug?

The following code type checks okay and has hover descriptions for methods, except they don't match the runtime behavior.

const x = new WebSocket("https://github.com")

try {
    x.setMaxListeners(1)
} catch (e) {
    console.error(e)
}
try {
    x.resume()
} catch (e) {
    console.error(e)
}

Image

What is the expected behavior?

The types correspond to the actual shape of the object.

> xy
WebSocket {}
> xy.__proto__
EventTarget [WebSocket] {
  url: [Getter],
  readyState: [Getter],
  bufferedAmount: [Getter],
  onopen: [Getter/Setter],
  onmessage: [Getter/Setter],
  onerror: [Getter/Setter],
  onclose: [Getter/Setter],
  protocol: [Getter],
  extensions: [Getter],
  binaryType: [Getter/Setter],
  send: [Function: send],
  close: [Function: close],
  ping: [Function: ping],
  pong: [Function: pong],
  terminate: [Function: terminate],
  CONNECTING: 0,
  OPEN: 1,
  CLOSING: 2,
  CLOSED: 3
}

What do you see instead?

1 | const x = new WebSocket("https://github.com")
2 | 
3 | try {
4 |     x.setMaxListeners(1)
          ^
TypeError: x.setMaxListeners is not a function. (In 'x.setMaxListeners(1)', 'x.setMaxListeners' is undefined)
      at /workspace/empty/index.ts:4:7

4 |     x.setMaxListeners(1)
5 | } catch (e) {
6 |     console.error(e)
7 | }
8 | try {
9 |     x.resume()
          ^
TypeError: x.resume is not a function. (In 'x.resume()', 'x.resume' is undefined)
      at /workspace/empty/index.ts:9:7

Additional information

No response

@lilnasy lilnasy added bug Something isn't working types An issue with TypeScript types labels Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working types An issue with TypeScript types
Projects
None yet
Development

No branches or pull requests

1 participant