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:
parent
2e1f3a56d1
commit
9014db7998
|
@ -1,7 +1,7 @@
|
||||||
/// <reference types="node" />
|
/// <reference types="node" />
|
||||||
/// <reference lib="dom" />
|
/// <reference lib="dom" />
|
||||||
|
|
||||||
import {Agent} from 'http';
|
import {RequestOptions} from 'http';
|
||||||
import {
|
import {
|
||||||
Blob,
|
Blob,
|
||||||
blobFrom,
|
blobFrom,
|
||||||
|
@ -98,7 +98,7 @@ export interface RequestInit {
|
||||||
referrerPolicy?: ReferrerPolicy;
|
referrerPolicy?: ReferrerPolicy;
|
||||||
|
|
||||||
// Node-fetch extensions to the whatwg/fetch spec
|
// Node-fetch extensions to the whatwg/fetch spec
|
||||||
agent?: Agent | ((parsedUrl: URL) => Agent);
|
agent?: RequestOptions['agent'] | ((parsedUrl: URL) => RequestOptions['agent']);
|
||||||
compress?: boolean;
|
compress?: boolean;
|
||||||
counter?: number;
|
counter?: number;
|
||||||
follow?: number;
|
follow?: number;
|
||||||
|
|
|
@ -78,6 +78,8 @@ async function run() {
|
||||||
expectAssignable<Body>(request);
|
expectAssignable<Body>(request);
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
|
new Request('url', {agent: false});
|
||||||
|
|
||||||
new Headers({Header: 'value'});
|
new Headers({Header: 'value'});
|
||||||
// new Headers(['header', 'value']); // should not work
|
// new Headers(['header', 'value']); // should not work
|
||||||
new Headers([['header', 'value']]);
|
new Headers([['header', 'value']]);
|
||||||
|
|
Loading…
Reference in New Issue