diff --git a/source/core/Ky.ts b/source/core/Ky.ts index 9147191a..638cb324 100644 --- a/source/core/Ky.ts +++ b/source/core/Ky.ts @@ -118,9 +118,13 @@ export class Ky { // eslint-disable-next-line complexity constructor(input: Input, options: Options = {}) { this._input = input; - const isCredentialsSupported = 'credentials' in Request.prototype; + const credentials + = this._input instanceof Request && 'credentials' in Request.prototype + ? this._input.credentials + : undefined; + this._options = { - credentials: isCredentialsSupported ? (this._input as Request).credentials : undefined, + ...(credentials && {credentials}), // For exactOptionalPropertyTypes ...options, headers: mergeHeaders((this._input as Request).headers, options.headers), hooks: deepMerge>( diff --git a/source/core/constants.ts b/source/core/constants.ts index 0f1fcdbd..27309629 100644 --- a/source/core/constants.ts +++ b/source/core/constants.ts @@ -76,4 +76,5 @@ export const requestOptionsRegistry: RequestInitRegistry = { window: true, dispatcher: true, duplex: true, + priority: true, }; diff --git a/source/types/options.ts b/source/types/options.ts index d69555f1..c391dbaa 100644 --- a/source/types/options.ts +++ b/source/types/options.ts @@ -245,7 +245,6 @@ Omit, hooks: Required; retry: Required; prefixUrl: string; - credentials?: Options['credentials']; // Allows credentials to be undefined for workers }; /** @@ -254,7 +253,7 @@ Normalized options passed to the `fetch` call and the `beforeRequest` hooks. export interface NormalizedOptions extends RequestInit { // eslint-disable-line @typescript-eslint/consistent-type-definitions -- This must stay an interface so that it can be extended outside of Ky for use in `ky.create`. // Extended from `RequestInit`, but ensured to be set (not optional). method: NonNullable; - credentials: RequestInit['credentials']; + credentials?: NonNullable; // Extended from custom `KyOptions`, but ensured to be set (not optional). retry: RetryOptions; diff --git a/tsconfig.json b/tsconfig.json index d9a03892..bbbb2278 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "@sindresorhus/tsconfig", + "compilerOptions": { + "exactOptionalPropertyTypes": true + }, "include": [ "source" ]