Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: connect option types #1790

Merged
merged 1 commit into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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