Skip to content
Myr

Make types compatible with both DOM and Node.js (#543)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alec Mev · committed by GitHub · parent d7b0abc · Browse files · 4 files+9 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+9 added−8 removed

  • tests:+1 added−1 removed
  • other:+8 added−7 removed

4 files+9 added−8 removed

modified:source/core/Ky.ts+1 added-1 removed
173 unmodified lines
174 // @ts-expect-error - Types are outdated.175 this._options.duplex = 'half';176 }177178 this.request = new globalThis.Request(this._input as RequestInfo, this._options as RequestInit);178 this.request = new globalThis.Request(this._input, this._options);179180 if (this._options.searchParams) {181 // eslint-disable-next-line unicorn/prevent-abbreviations182 const textSearchParams = typeof this._options.searchParams === 'string'
181 unmodified lines
modified:source/types/options.ts+5 added-4 removed
20 unmodified lines
21 */22 totalBytes: number;23};2425// Not HeadersInit directly because @types/node doesn't export it25export type KyHeadersInit = HeadersInit | Record<string, string | undefined>;26export type KyHeadersInit = NonNullable<RequestInit['headers']> | Record<string, string | undefined>;2728/**29Custom Ky options30*/
146 unmodified lines
177178 const json = await ky('https://example.com', {fetch}).json();179 ```180 */180 fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;181 fetch?: (input: Input, init?: RequestInit) => Promise<Response>;182};183184/**185Each key from KyOptions is present and set to `true`.
65 unmodified lines
251Normalized options passed to the `fetch` call and the `beforeRequest` hooks.252*/253export 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`.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']>;257258 // Extended from custom `KyOptions`, but ensured to be set (not optional).259 retry: RetryOptions;260 prefixUrl: string;
4 unmodified lines
modified:source/utils/merge.ts+2 added-2 removed
modified:test/headers.ts+1 added-1 removed
21 unmodified lines
22 // Some old browsers throw for new Headers(undefined) or new Headers(null)23 // so we check that Ky never does that and passes an empty object instead.24 // See: https://github.com/sindresorhus/ky/issues/26025 globalThis.Headers = class Headers extends OriginalHeaders {26 constructor(headersInit?: HeadersInit | undefined) {26 constructor(headersInit?: RequestInit['headers']) {27 t.deepEqual(headersInit, {});28 super(headersInit);29 }30 };
406 unmodified lines