diff --git a/.changeset/tidy-plants-deliver.md b/.changeset/tidy-plants-deliver.md new file mode 100644 index 0000000..044ced6 --- /dev/null +++ b/.changeset/tidy-plants-deliver.md @@ -0,0 +1,5 @@ +--- +"x-fetch": patch +--- + +fix: known typings issue of `type` field diff --git a/src/index.ts b/src/index.ts index 0c39293..4cc0cc5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,11 +14,15 @@ export const ApiMethod = { export type ApiMethod = ValueOf -export interface FetchApiOptions extends Omit { +export interface FetchApiBaseOptions + extends Omit { method?: ApiMethod body?: BodyInit | object query?: URLSearchParametersOptions json?: boolean +} + +export interface FetchApiOptions extends FetchApiBaseOptions { type?: 'arrayBuffer' | 'blob' | 'json' | 'text' | null } @@ -67,23 +71,24 @@ export const createFetchApi = () => { function fetchApi( url: string, - options: FetchApiOptions & { type: null }, + options: FetchApiBaseOptions & { type: null }, ): Promise + // @ts-expect-error -- no idea, it sucks function fetchApi( url: string, - options: FetchApiOptions & { type: 'arraybuffer' }, + options: FetchApiBaseOptions & { type: 'arraybuffer' }, ): Promise function fetchApi( url: string, - options: FetchApiOptions & { type: 'blob' }, + options: FetchApiBaseOptions & { type: 'blob' }, ): Promise function fetchApi( url: string, - options: FetchApiOptions & { type: 'text' }, + options: FetchApiBaseOptions & { type: 'text' }, ): Promise function fetchApi( url: string, - options?: FetchApiOptions & { type?: 'json' }, + options?: FetchApiBaseOptions & { type?: 'json' }, ): Promise // eslint-disable-next-line sonarjs/cognitive-complexity async function fetchApi(