File tree 4 files changed +9
-8
lines changed
4 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ export class Ky {
175
175
this . _options . duplex = 'half' ;
176
176
}
177
177
178
- this . request = new globalThis . Request ( this . _input as RequestInfo , this . _options as RequestInit ) ;
178
+ this . request = new globalThis . Request ( this . _input , this . _options ) ;
179
179
180
180
if ( this . _options . searchParams ) {
181
181
// eslint-disable-next-line unicorn/prevent-abbreviations
Original file line number Diff line number Diff line change @@ -22,7 +22,8 @@ export type DownloadProgress = {
22
22
totalBytes : number ;
23
23
} ;
24
24
25
- export type KyHeadersInit = HeadersInit | Record < string , string | undefined > ;
25
+ // Not HeadersInit directly because @types /node doesn't export it
26
+ export type KyHeadersInit = NonNullable < RequestInit [ 'headers' ] > | Record < string , string | undefined > ;
26
27
27
28
/**
28
29
Custom Ky options
@@ -177,7 +178,7 @@ export type KyOptions = {
177
178
const json = await ky('https://example.com', {fetch}).json();
178
179
```
179
180
*/
180
- fetch ?: ( input : RequestInfo , init ?: RequestInit ) => Promise < Response > ;
181
+ fetch ?: ( input : Input , init ?: RequestInit ) => Promise < Response > ;
181
182
} ;
182
183
183
184
/**
@@ -251,8 +252,8 @@ Normalized options passed to the `fetch` call and the `beforeRequest` hooks.
251
252
*/
252
253
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`.
253
254
// Extended from `RequestInit`, but ensured to be set (not optional).
254
- method : RequestInit [ 'method' ] ;
255
- credentials : RequestInit [ 'credentials' ] ;
255
+ method : NonNullable < RequestInit [ 'method' ] > ;
256
+ credentials : NonNullable < RequestInit [ 'credentials' ] > ;
256
257
257
258
// Extended from custom `KyOptions`, but ensured to be set (not optional).
258
259
retry : RetryOptions ;
Original file line number Diff line number Diff line change @@ -12,9 +12,9 @@ export const validateAndMerge = (...sources: Array<Partial<Options> | undefined>
12
12
} ;
13
13
14
14
export const mergeHeaders = ( source1 : KyHeadersInit = { } , source2 : KyHeadersInit = { } ) => {
15
- const result = new globalThis . Headers ( source1 as HeadersInit ) ;
15
+ const result = new globalThis . Headers ( source1 as RequestInit [ 'headers' ] ) ;
16
16
const isHeadersInstance = source2 instanceof globalThis . Headers ;
17
- const source = new globalThis . Headers ( source2 as HeadersInit ) ;
17
+ const source = new globalThis . Headers ( source2 as RequestInit [ 'headers' ] ) ;
18
18
19
19
for ( const [ key , value ] of source . entries ( ) ) {
20
20
if ( ( isHeadersInstance && value === 'undefined' ) || value === undefined ) {
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ test.serial('works with nullish headers even in old browsers', async t => {
23
23
// so we check that Ky never does that and passes an empty object instead.
24
24
// See: https://github.com/sindresorhus/ky/issues/260
25
25
globalThis . Headers = class Headers extends OriginalHeaders {
26
- constructor ( headersInit ?: HeadersInit | undefined ) {
26
+ constructor ( headersInit ?: RequestInit [ 'headers' ] ) {
27
27
t . deepEqual ( headersInit , { } ) ;
28
28
super ( headersInit ) ;
29
29
}
You can’t perform that action at this time.
0 commit comments