Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exactOptionalPropertyTypes, fix TypeScript 5.4 #565

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Required<Hooks>>(
Expand Down
1 change: 1 addition & 0 deletions source/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ export const requestOptionsRegistry: RequestInitRegistry = {
window: true,
dispatcher: true,
duplex: true,
priority: true,
};
3 changes: 1 addition & 2 deletions source/types/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ Omit<Options, 'hooks' | 'retry'>,
hooks: Required<Hooks>;
retry: Required<RetryOptions>;
prefixUrl: string;
credentials?: Options['credentials']; // Allows credentials to be undefined for workers
};

/**
Expand All @@ -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<RequestInit['method']>;
credentials: RequestInit['credentials'];
credentials?: NonNullable<RequestInit['credentials']>;

// Extended from custom `KyOptions`, but ensured to be set (not optional).
retry: RetryOptions;
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "@sindresorhus/tsconfig",
"compilerOptions": {
"exactOptionalPropertyTypes": true
},
"include": [
"source"
]
Expand Down