Skip to content

Commit e95a743

Browse files
author
johannesmartikkala
committed
fix/correctly-infer-optional-query-parameters
1 parent ef984cf commit e95a743

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/types.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,16 @@ type _CreateFetch<OP, Q = never> = [Q] extends [never]
124124
: (query: Q) => TypedFetch<OP>
125125

126126
export type CreateFetch<M, OP> = M extends 'post' | 'put' | 'patch' | 'delete'
127-
? OP extends { parameters: { query: infer Q } }
128-
? _CreateFetch<OP, { [K in keyof Q]: true | 1 }>
127+
? OP extends {
128+
parameters: {
129+
query?: infer Q;
130+
};
131+
}
132+
? [keyof Q] extends [never]
133+
? _CreateFetch<OP>
134+
: _CreateFetch<OP, { [K in keyof Q]: true | 1; }>
129135
: _CreateFetch<OP>
130-
: _CreateFetch<OP>
136+
: _CreateFetch<OP>;
131137

132138
export type Middleware = (
133139
url: string,

0 commit comments

Comments
 (0)