Skip to content

Commit 41d60d6

Browse files
authored
fix: connect option types (nodejs#1790)
1 parent ac54432 commit 41d60d6

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/api/Connector.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ Once you call `buildConnector`, it will return a connector function, which takes
2424
* **hostname** `string` (required)
2525
* **host** `string` (optional)
2626
* **protocol** `string` (required)
27-
* **port** `number` (required)
27+
* **port** `string` (required)
2828
* **servername** `string` (optional)
29+
* **localAddress** `string | null` (optional) Local address the socket should connect from.
30+
* **httpSocket** `Socket` (optional) Establish secure connection on a given socket rather than creating a new socket. It can only be sent on TLS update.
2931

3032
### Basic example
3133

test/types/connector.test-d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {expectAssignable} from 'tsd'
22
import { Client, buildConnector } from '../..'
33
import {ConnectionOptions, TLSSocket} from 'tls'
4+
import {Socket} from 'net'
45
import {IpcNetConnectOpts, NetConnectOpts, TcpNetConnectOpts} from "net";
56

67
const connector = buildConnector({ rejectUnauthorized: false })
@@ -25,3 +26,11 @@ expectAssignable<buildConnector.BuildOptions>({
2526
checkServerIdentity: () => undefined, // Test if ConnectionOptions is assignable
2627
localPort: 1234, // Test if TcpNetConnectOpts is assignable
2728
});
29+
30+
expectAssignable<buildConnector.Options>({
31+
protocol: "http",
32+
hostname: "example.com",
33+
port: "",
34+
localAddress: "127.0.0.1",
35+
httpSocket: new Socket(),
36+
});

types/connector.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ declare namespace buildConnector {
1616
hostname: string
1717
host?: string
1818
protocol: string
19-
port: number
19+
port: string
2020
servername?: string
21+
localAddress?: string | null
22+
httpSocket?: Socket
2123
}
2224

2325
export type Callback = (...args: CallbackArgs) => void

0 commit comments

Comments
 (0)