Skip to content

Commit ccf86f9

Browse files
authored
Declare correct ws options type (#338)
1 parent c627a42 commit ccf86f9

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

lib/client.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type { ClientRequestArgs } from "http";
2+
import type { ClientOptions } from "ws";
3+
14
// Same as exported type in @hapi/hapi v20
25
type HTTP_METHODS = 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' |
36
'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' |
@@ -173,7 +176,7 @@ export class Client {
173176
constructor(
174177
url: `ws://${string}` | `wss://${string}`,
175178
options?: {
176-
ws?: string | string[];
179+
ws?: ClientOptions | ClientRequestArgs;
177180
timeout?: number | boolean;
178181
});
179182

@@ -369,4 +372,4 @@ export class Client {
369372
* `client.connect()`
370373
*/
371374
reauthenticate(auth: ClientConnectOptions['auth']): Promise<unknown>;
372-
}
375+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@hapi/iron": "^7.0.1",
2626
"@hapi/teamwork": "^6.0.0",
2727
"@hapi/validate": "^2.0.1",
28+
"@types/ws": "^8.5.13",
2829
"ws": "^8.18.0"
2930
},
3031
"devDependencies": {

test/types/client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import { Client } from '../../lib/client';
77

88
const init = () => {
99

10-
const client = new Client('ws://localhost');
10+
const client = new Client('ws://localhost', {
11+
ws: { // optional
12+
origin: 'http://localhost:12345',
13+
maxPayload: 1000,
14+
headers: { cookie: 'xnes=123' }
15+
}
16+
});
1117

1218
client.connect()
1319

0 commit comments

Comments
 (0)