From ccf86f9d0ceedb039efb601bc1c18a349c9797bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Bly=C5=BE=C4=97?= Date: Wed, 8 Jan 2025 23:42:11 +0200 Subject: [PATCH] Declare correct `ws` options type (#338) --- lib/client.d.ts | 7 +++++-- package.json | 1 + test/types/client.ts | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/client.d.ts b/lib/client.d.ts index 76a622c..69c20cf 100644 --- a/lib/client.d.ts +++ b/lib/client.d.ts @@ -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' | @@ -173,7 +176,7 @@ export class Client { constructor( url: `ws://${string}` | `wss://${string}`, options?: { - ws?: string | string[]; + ws?: ClientOptions | ClientRequestArgs; timeout?: number | boolean; }); @@ -369,4 +372,4 @@ export class Client { * `client.connect()` */ reauthenticate(auth: ClientConnectOptions['auth']): Promise; -} \ No newline at end of file +} diff --git a/package.json b/package.json index 67cfddc..223fb7b 100755 --- a/package.json +++ b/package.json @@ -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.18.0" }, "devDependencies": { diff --git a/test/types/client.ts b/test/types/client.ts index d8bdf77..293379f 100644 --- a/test/types/client.ts +++ b/test/types/client.ts @@ -7,7 +7,13 @@ import { Client } from '../../lib/client'; const init = () => { - const client = new Client('ws://localhost'); + const client = new Client('ws://localhost', { + ws: { // optional + origin: 'http://localhost:12345', + maxPayload: 1000, + headers: { cookie: 'xnes=123' } + } + }); client.connect()