types: support `agent: false` (#1502)

The `agent` option is (after being potentially called as as function)
passed directly to `http.request`. This is allowed to be
a boolean; `http.request` interprets `agent: false` as
"allocate a one-off Agent for this request", which is
distinct from `agent: undefined` which means to use a
default shared agent.

This PR updates the TS types to match the existing behavior.
This commit is contained in:
David Glasser 2022-02-09 14:22:25 -08:00 committed by GitHub
parent 2e1f3a56d1
commit 9014db7998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

4
@types/index.d.ts vendored
View File

@ -1,7 +1,7 @@
/// <reference types="node" />
/// <reference lib="dom" />
import {Agent} from 'http';
import {RequestOptions} from 'http';
import {
Blob,
blobFrom,
@ -98,7 +98,7 @@ export interface RequestInit {
referrerPolicy?: ReferrerPolicy;
// Node-fetch extensions to the whatwg/fetch spec
agent?: Agent | ((parsedUrl: URL) => Agent);
agent?: RequestOptions['agent'] | ((parsedUrl: URL) => RequestOptions['agent']);
compress?: boolean;
counter?: number;
follow?: number;

View File

@ -78,6 +78,8 @@ async function run() {
expectAssignable<Body>(request);
/* eslint-disable no-new */
new Request('url', {agent: false});
new Headers({Header: 'value'});
// new Headers(['header', 'value']); // should not work
new Headers([['header', 'value']]);