Skip to content

Commit

Permalink
fix: connect option types (#1790)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaciras committed Nov 29, 2022
1 parent ac54432 commit 41d60d6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/api/Connector.md
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions 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 })
Expand All @@ -25,3 +26,11 @@ expectAssignable<buildConnector.BuildOptions>({
checkServerIdentity: () => undefined, // Test if ConnectionOptions is assignable
localPort: 1234, // Test if TcpNetConnectOpts is assignable
});

expectAssignable<buildConnector.Options>({
protocol: "http",
hostname: "example.com",
port: "",
localAddress: "127.0.0.1",
httpSocket: new Socket(),
});
4 changes: 3 additions & 1 deletion types/connector.d.ts
Expand Up @@ -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
Expand Down

0 comments on commit 41d60d6

Please sign in to comment.