From c4980f4da0dcb8e42be80abd8f42d5fb9cf4d1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 28 Aug 2023 23:33:55 +0200 Subject: [PATCH] fix(fetch): add HTTPS Agent types to `fetch` & `Request` (#78) * fix: add typings for HTTPS agent for fetch and Request (#18) Co-authored-by: Clifford Fajardo * chore: fix changeset --------- Co-authored-by: Clifford Fajardo Co-authored-by: Clifford Fajardo Co-authored-by: Irakli Gozalishvili --- .changeset/polite-poets-enjoy.md | 5 +++++ packages/fetch/src/fetch.js | 8 ++++---- packages/fetch/src/request.js | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 .changeset/polite-poets-enjoy.md diff --git a/.changeset/polite-poets-enjoy.md b/.changeset/polite-poets-enjoy.md new file mode 100644 index 0000000..9a888bd --- /dev/null +++ b/.changeset/polite-poets-enjoy.md @@ -0,0 +1,5 @@ +--- +"@web-std/fetch": minor +--- + +expose `RequestExtraOptions` to `fetch` & add `HTTPs.agent` to types diff --git a/packages/fetch/src/fetch.js b/packages/fetch/src/fetch.js index 20ebd21..59cf73e 100644 --- a/packages/fetch/src/fetch.js +++ b/packages/fetch/src/fetch.js @@ -33,7 +33,7 @@ const supportedSchemas = new Set(['data:', 'http:', 'https:', 'file:']); * Fetch function * * @param {string | URL | import('./request').default} url - Absolute url or Request instance - * @param {RequestInit} [options_] - Fetch options + * @param {RequestInit & import('./request.js').RequestExtraOptions} [options_] - Fetch options * @return {Promise} */ async function fetch(url, options_ = {}) { @@ -319,9 +319,9 @@ async function fetch(url, options_ = {}) { } /** - * - * @param {import('http').ClientRequest} request - * @param {(error:Error) => void} errorCallback + * + * @param {import('http').ClientRequest} request + * @param {(error:Error) => void} errorCallback */ function fixResponseChunkedTransferBadEnding(request, errorCallback) { const LAST_CHUNK = Buffer.from('0\r\n\r\n'); diff --git a/packages/fetch/src/request.js b/packages/fetch/src/request.js index 502a121..a6a9fed 100644 --- a/packages/fetch/src/request.js +++ b/packages/fetch/src/request.js @@ -53,7 +53,7 @@ const isRequest = object => { * @property {number} [highWaterMark] * @property {boolean} [insecureHTTPParser] * - * @typedef {((url:URL) => import('http').Agent) | import('http').Agent} Agent + * @typedef {((url:URL) => import('http').Agent | import('https').Agent) | import('http').Agent | import('https').Agent} Agent * * @typedef {Object} RequestOptions * @property {string} [method]