Skip to content

Commit

Permalink
fix: declare correct ws options type
Browse files Browse the repository at this point in the history
The original string | string[] seems to have been a mistake because the ws package client takes 3 arguments, of which the middle one (protocols) is the string | string[], but it is optional. When it is left out - it becomes the options object instead: https://github.com/websockets/ws/blob/c798dd4ee20efb2d7591b5659839ad05cdb3eb70/lib/websocket.js#L80

The type information is covered in jsdoc: https://github.com/websockets/ws/blob/c798dd4ee20efb2d7591b5659839ad05cdb3eb70/lib/websocket.js#L627

A more complete typing information is exposed by @types/ws, though.
  • Loading branch information
dominykas committed Jan 6, 2025
1 parent 2132240 commit 96fc4d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { ClientRequestArgs } from "http";
import type { ClientOptions } from "ws";

// Same as exported type in @hapi/hapi v20
type HTTP_METHODS = 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' |
'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' |
Expand Down Expand Up @@ -173,7 +176,7 @@ export class Client {
constructor(
url: `ws://${string}` | `wss://${string}`,
options?: {
ws?: string | string[];
ws?: ClientOptions | ClientRequestArgs;
timeout?: number | boolean;
});

Expand Down Expand Up @@ -369,4 +372,4 @@ export class Client {
* `client.connect()`
*/
reauthenticate(auth: ClientConnectOptions['auth']): Promise<unknown>;
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@hapi/iron": "^7.0.1",
"@hapi/teamwork": "^6.0.0",
"@hapi/validate": "^2.0.1",
"@types/ws": "^8.5.13",
"ws": "^8.17.1"
},
"devDependencies": {
Expand Down

0 comments on commit 96fc4d8

Please sign in to comment.