Skip to content

Commit 08f912d

Browse files
authoredMar 24, 2024··
Fix exactOptionalPropertyTypes and compatibility with TypeScript 5.4 (#565)
1 parent 051d7ab commit 08f912d

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed
 

‎source/core/Ky.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ export class Ky {
118118
// eslint-disable-next-line complexity
119119
constructor(input: Input, options: Options = {}) {
120120
this._input = input;
121-
const isCredentialsSupported = 'credentials' in Request.prototype;
121+
const credentials
122+
= this._input instanceof Request && 'credentials' in Request.prototype
123+
? this._input.credentials
124+
: undefined;
125+
122126
this._options = {
123-
credentials: isCredentialsSupported ? (this._input as Request).credentials : undefined,
127+
...(credentials && {credentials}), // For exactOptionalPropertyTypes
124128
...options,
125129
headers: mergeHeaders((this._input as Request).headers, options.headers),
126130
hooks: deepMerge<Required<Hooks>>(

‎source/core/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ export const requestOptionsRegistry: RequestInitRegistry = {
7676
window: true,
7777
dispatcher: true,
7878
duplex: true,
79+
priority: true,
7980
};

‎source/types/options.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ Omit<Options, 'hooks' | 'retry'>,
245245
hooks: Required<Hooks>;
246246
retry: Required<RetryOptions>;
247247
prefixUrl: string;
248-
credentials?: Options['credentials']; // Allows credentials to be undefined for workers
249248
};
250249

251250
/**
@@ -254,7 +253,7 @@ Normalized options passed to the `fetch` call and the `beforeRequest` hooks.
254253
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`.
255254
// Extended from `RequestInit`, but ensured to be set (not optional).
256255
method: NonNullable<RequestInit['method']>;
257-
credentials: RequestInit['credentials'];
256+
credentials?: NonNullable<RequestInit['credentials']>;
258257

259258
// Extended from custom `KyOptions`, but ensured to be set (not optional).
260259
retry: RetryOptions;

‎tsconfig.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"extends": "@sindresorhus/tsconfig",
3+
"compilerOptions": {
4+
"exactOptionalPropertyTypes": true
5+
},
36
"include": [
47
"source"
58
]

0 commit comments

Comments
 (0)
Please sign in to comment.