diff --git a/source/core/Ky.ts b/source/core/Ky.ts index 5662f45e..6d7bc0fd 100644 --- a/source/core/Ky.ts +++ b/source/core/Ky.ts @@ -170,13 +170,13 @@ export class Ky { this._options.signal = this.abortController.signal; } - this.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit); - if (supportsRequestStreams) { // @ts-expect-error - Types are outdated. - this.request.duplex = 'half'; + this._options.duplex = 'half'; } + this.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit); + if (this._options.searchParams) { // eslint-disable-next-line unicorn/prevent-abbreviations const textSearchParams = typeof this._options.searchParams === 'string' @@ -194,7 +194,8 @@ export class Ky { this.request.headers.delete('content-type'); } - this.request = new globalThis.Request(new globalThis.Request(url, this.request), this._options as RequestInit); + // The spread of `this.request` is required as otherwise it misses the `duplex` option for some reason and throws. + this.request = new globalThis.Request(new globalThis.Request(url, {...this.request}), this._options as RequestInit); } if (this._options.json !== undefined) {