From 9014db79989b57c9f145c02e51f9374a5444378b Mon Sep 17 00:00:00 2001 From: David Glasser Date: Wed, 9 Feb 2022 14:22:25 -0800 Subject: [PATCH] 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. --- @types/index.d.ts | 4 ++-- @types/index.test-d.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/@types/index.d.ts b/@types/index.d.ts index c0e78bc6f..1e36d66cd 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -1,7 +1,7 @@ /// /// -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; diff --git a/@types/index.test-d.ts b/@types/index.test-d.ts index 4b24dcbb1..627766599 100644 --- a/@types/index.test-d.ts +++ b/@types/index.test-d.ts @@ -78,6 +78,8 @@ async function run() { expectAssignable(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']]);