#WebSocket with WebSocket.ClientOptions?

1 messages · Page 1 of 1 (latest)

dreamy parrot
#

Hi there,

I'm looking to connect to an external WebSocket. However, the WebSocket requires that certain headers be present.

I see that the WebSocket constructor accepts WebSocket.ClientOptions as a second or third argument:

declare class WebSocket extends EventEmitter {
  // ...
  constructor(address: string | URL, options?: WebSocket.ClientOptions | ClientRequestArgs);
  constructor(
    address: string | URL,
    protocols?: string | string[],
    options?: WebSocket.ClientOptions | ClientRequestArgs,
  );
interface ClientOptions extends SecureContextOptions {
  // ...
  headers?: { [key: string]: string } | undefined;

However, I can't seem to use WebSocket.ClientOptions with a new WebSocket at all — see attached.

Am I missing something?

I can do this with ws, but would prefer not to.

west palm
#

Those seem like the types for the polyfill bun has for the ws package

dreamy parrot
#

Alrighty, so it sounds like my option is to continue using ws. 😦