Skip to content

Commit

Permalink
types: support agent: false (#1502)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
glasser committed Feb 9, 2022
1 parent 2e1f3a5 commit 9014db7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions @types/index.d.ts
@@ -1,7 +1,7 @@
/// <reference types="node" />
/// <reference lib="dom" />

import {Agent} from 'http';
import {RequestOptions} from 'http';
import {
Blob,
blobFrom,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions @types/index.test-d.ts
Expand Up @@ -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']]);
Expand Down

0 comments on commit 9014db7

Please sign in to comment.