question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript defs for close are missing third argument

See original GitHub issue

ReconnectingWebsocket extends WebSocket but doesn’t redefine the close method to take the third “options” parameter.

Closing a reconnecting websocket like this:

rws.close(1000, '', opts);

Results in a typescript error; Expected 0-2 arguments, but got 3.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
bennycodecommented, Dec 13, 2017

I got the same issue with reconnecting-websocket v3.2.2:

unbenannt

Here is my code:

const Html5WebSocket = require('html5-websocket');
const ReconnectingWebsocket = require('reconnecting-websocket');

private socket: WebSocket;

// ...

public connect(clientId?: string): void { 
  this.socket = new ReconnectingWebsocket(...);
}

public disconnect(): void {
  // TS2554: Expected 0-2 arguments, but got 3.
  this.socket.close(1000, '', {keepClosed: true, fastClose: true, delay: 0});
}

Luckily there is a workaround:

public disconnect(): void {
  const socket: any = this.socket; // Cast 'WebSocket' into 'any' in order to supply a third parameter
  this.socket.close(1000, '', {keepClosed: true, fastClose: true, delay: 0});
}

Source: https://github.com/wireapp/wire-web-packages/pull/114

0reactions
bennycodecommented, Oct 30, 2019

@pladaria I checked the “close” function of v4.2.0 and it is defined to accept only 2 parameters (“code” and “reason”), so I guess there is no more support for a third (“options”) parameter?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript third party definition file - class missing method ...
I am attempting to use the createAccount() method and the typescript compiler is giving me an error. I'd like to be able to...
Read more >
Documentation - More on Functions - TypeScript
Functions are the basic building block of any application, whether they're local functions, imported from another module, or methods on a class.
Read more >
Typescript: missing type definitions. · Issue #8642 - GitHub
I am opening this issue to report missing types when I notice that. Here is the first: Cookie options type does not have...
Read more >
typescript-cheatsheet - GitHub Pages
In TypeScript any argument of a function may be assigned a type no matter how ... the union types because they have a...
Read more >
TypeScript Programming with Visual Studio Code
Signature help. As you write a TypeScript function call, VS Code shows information about the function signature and highlights the parameter that you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found