From c4c06363e41925ed7ddd701f90a2451958238668 Mon Sep 17 00:00:00 2001 From: Kaciras Date: Tue, 29 Nov 2022 16:44:59 +0800 Subject: [PATCH] fix: connect option types (#1790) --- docs/api/Connector.md | 4 +++- test/types/connector.test-d.ts | 9 +++++++++ types/connector.d.ts | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/api/Connector.md b/docs/api/Connector.md index fe446b46e62..7c966507e5f 100644 --- a/docs/api/Connector.md +++ b/docs/api/Connector.md @@ -24,8 +24,10 @@ Once you call `buildConnector`, it will return a connector function, which takes * **hostname** `string` (required) * **host** `string` (optional) * **protocol** `string` (required) -* **port** `number` (required) +* **port** `string` (required) * **servername** `string` (optional) +* **localAddress** `string | null` (optional) Local address the socket should connect from. +* **httpSocket** `Socket` (optional) Establish secure connection on a given socket rather than creating a new socket. It can only be sent on TLS update. ### Basic example diff --git a/test/types/connector.test-d.ts b/test/types/connector.test-d.ts index ba40f0e6c08..1437d6f333d 100644 --- a/test/types/connector.test-d.ts +++ b/test/types/connector.test-d.ts @@ -1,6 +1,7 @@ import {expectAssignable} from 'tsd' import { Client, buildConnector } from '../..' import {ConnectionOptions, TLSSocket} from 'tls' +import {Socket} from 'net' import {IpcNetConnectOpts, NetConnectOpts, TcpNetConnectOpts} from "net"; const connector = buildConnector({ rejectUnauthorized: false }) @@ -25,3 +26,11 @@ expectAssignable({ checkServerIdentity: () => undefined, // Test if ConnectionOptions is assignable localPort: 1234, // Test if TcpNetConnectOpts is assignable }); + +expectAssignable({ + protocol: "http", + hostname: "example.com", + port: "", + localAddress: "127.0.0.1", + httpSocket: new Socket(), +}); diff --git a/types/connector.d.ts b/types/connector.d.ts index 8a425d2972c..2b28771af2a 100644 --- a/types/connector.d.ts +++ b/types/connector.d.ts @@ -16,8 +16,10 @@ declare namespace buildConnector { hostname: string host?: string protocol: string - port: number + port: string servername?: string + localAddress?: string | null + httpSocket?: Socket } export type Callback = (...args: CallbackArgs) => void