diff --git a/src/types.ts b/src/types.ts index 9d51fb00..0b2c82fa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -117,7 +117,7 @@ type _CreateFetch = [Q] extends [never] export type CreateFetch = M extends 'post' | 'put' | 'patch' | 'delete' ? OP extends { parameters: { query: infer Q } } - ? _CreateFetch + ? _CreateFetch : _CreateFetch : _CreateFetch diff --git a/test/fetch.test.ts b/test/fetch.test.ts index 974dbdda..b3cbebf5 100644 --- a/test/fetch.test.ts +++ b/test/fetch.test.ts @@ -86,7 +86,7 @@ describe('fetch', () => { const fun = fetcher .path('/bodyquery/{id}') .method(method) - .create({ scalar: 1 }) + .create({ scalar: 1, optional: 1 }) const { data } = await fun({ id: 1, @@ -235,7 +235,7 @@ describe('fetch', () => { const fun = fetcher .path('/bodyquery/{id}') .method('post') - .create({ scalar: 1 }) + .create({ scalar: 1, optional: 1 }) const captured = { url: '', body: '' } diff --git a/test/infer.test.ts b/test/infer.test.ts index 03ff5cb1..a6c3ea6b 100644 --- a/test/infer.test.ts +++ b/test/infer.test.ts @@ -9,6 +9,7 @@ import { OpReturnType, TypedFetch, } from '../src' +import { paths } from './paths' import { paths as paths2 } from './examples/stripe-openapi2' import { paths as paths3 } from './examples/stripe-openapi3' @@ -40,6 +41,23 @@ interface Openapi3 { type Same = A extends B ? (B extends A ? true : false) : false describe('infer', () => { + it('queryParams', () => { + const fetcher = Fetcher.for() + + fetcher + .path('/bodyquery/{id}') + .method('post') + // @ts-expect-error // Missing the optional param is wrong + .create({ scalar: 1 }) + + fetcher + .path('/bodyquery/{id}') + .method('post') + .create({ scalar: 1, optional: 1 }) + + expect(true).toBe(true) + }) + it('argument', () => { const same: Same = true expect(same).toBe(true) diff --git a/test/paths.ts b/test/paths.ts index afc3831a..3b1c030c 100644 --- a/test/paths.ts +++ b/test/paths.ts @@ -9,7 +9,7 @@ export type Data = { type Query = { parameters: { path: { a: number; b: string } - query: { scalar: string; list: string[] } + query: { scalar: string; list: string[]; optional?: string } } responses: { 200: { schema: Data } } } @@ -33,7 +33,7 @@ type BodyArray = { type BodyAndQuery = { parameters: { path: { id: number } - query: { scalar: string } + query: { scalar: string; optional?: string } body: { payload: { list: string[] } } } responses: { 201: { schema: Data } }