diff --git a/source/core/Ky.ts b/source/core/Ky.ts index 62e3d977..9147191a 100644 --- a/source/core/Ky.ts +++ b/source/core/Ky.ts @@ -118,9 +118,9 @@ export class Ky { // eslint-disable-next-line complexity constructor(input: Input, options: Options = {}) { this._input = input; + const isCredentialsSupported = 'credentials' in Request.prototype; this._options = { - // TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208 - credentials: (this._input as Request).credentials || 'same-origin', + credentials: isCredentialsSupported ? (this._input as Request).credentials : undefined, ...options, headers: mergeHeaders((this._input as Request).headers, options.headers), hooks: deepMerge>( diff --git a/source/types/options.ts b/source/types/options.ts index 7fd40683..d69555f1 100644 --- a/source/types/options.ts +++ b/source/types/options.ts @@ -239,12 +239,13 @@ export interface Options extends KyOptions, Omit { // es export type InternalOptions = Required< Omit, -'credentials' | 'fetch' | 'prefixUrl' | 'timeout' +'fetch' | 'prefixUrl' | 'timeout' > & { headers: Required; hooks: Required; retry: Required; prefixUrl: string; + credentials?: Options['credentials']; // Allows credentials to be undefined for workers }; /** @@ -253,7 +254,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: NonNullable; + credentials: RequestInit['credentials']; // Extended from custom `KyOptions`, but ensured to be set (not optional). retry: RetryOptions;