diff --git a/src/types.ts b/src/types.ts index 185bb709..4e095659 100644 --- a/src/types.ts +++ b/src/types.ts @@ -15,6 +15,7 @@ export type OpenapiPaths = { // https://github.com/ajaishankar/openapi-typescript-fetch/issues/71#issuecomment-2847360598 type NonNever = [T] extends [never | undefined] ? unknown : T +type IsAny = 0 extends (1 & T) ? true : false; export type OpArgType = OP extends { parameters?: { @@ -119,15 +120,21 @@ export type FetchErrorType = F extends TypedFetch ? OpErrorType : never -type _CreateFetch = [Q] extends [never] - ? () => TypedFetch - : (query: Q) => TypedFetch - export type CreateFetch = M extends 'post' | 'put' | 'patch' | 'delete' - ? OP extends { parameters: { query: infer Q } } - ? _CreateFetch - : _CreateFetch - : _CreateFetch + ? OP extends { + parameters: { + query?: infer Q; + }; + } + ? IsAny extends true + ? () => TypedFetch + : [keyof Q] extends [never] + ? () => TypedFetch + : {} extends Q + ? (query?: { [K in keyof Q]: true | 1 }) => TypedFetch + : (query: { [K in keyof Q]: true | 1 }) => TypedFetch + : () => TypedFetch + : () => TypedFetch; export type Middleware = ( url: string,