From 720bb877f927d5da1da7f2425a8a3b1e154c3fea Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 14 Dec 2023 17:23:28 +0800 Subject: [PATCH 1/2] fix: known typings issue of `type` field --- src/index.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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( From 570aef1df3858b8ae376a8d70951d3e748dc5ba3 Mon Sep 17 00:00:00 2001 From: JounQin Date: Thu, 14 Dec 2023 17:24:14 +0800 Subject: [PATCH 2/2] Create tidy-plants-deliver.md --- .changeset/tidy-plants-deliver.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tidy-plants-deliver.md 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