File tree Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Expand file tree Collapse file tree 4 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ type _CreateFetch<OP, Q = never> = [Q] extends [never]
123123
124124export type CreateFetch < M , OP > = M extends 'post' | 'put' | 'patch' | 'delete'
125125 ? OP extends { parameters : { query : infer Q } }
126- ? _CreateFetch < OP , { [ K in keyof Q ] : true | 1 } >
126+ ? _CreateFetch < OP , { [ K in keyof Q ] -? : true | 1 } >
127127 : _CreateFetch < OP >
128128 : _CreateFetch < OP >
129129
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ describe('fetch', () => {
8686 const fun = fetcher
8787 . path ( '/bodyquery/{id}' )
8888 . method ( method )
89- . create ( { scalar : 1 } )
89+ . create ( { scalar : 1 , optional : 1 } )
9090
9191 const { data } = await fun ( {
9292 id : 1 ,
@@ -235,7 +235,7 @@ describe('fetch', () => {
235235 const fun = fetcher
236236 . path ( '/bodyquery/{id}' )
237237 . method ( 'post' )
238- . create ( { scalar : 1 } )
238+ . create ( { scalar : 1 , optional : 1 } )
239239
240240 const captured = { url : '' , body : '' }
241241
Original file line number Diff line number Diff line change 99 OpReturnType ,
1010 TypedFetch ,
1111} from '../src'
12+ import { paths } from './paths'
1213import { paths as paths2 } from './examples/stripe-openapi2'
1314import { paths as paths3 } from './examples/stripe-openapi3'
1415
@@ -40,6 +41,23 @@ interface Openapi3 {
4041type Same < A , B > = A extends B ? ( B extends A ? true : false ) : false
4142
4243describe ( 'infer' , ( ) => {
44+ it ( 'queryParams' , ( ) => {
45+ const fetcher = Fetcher . for < paths > ( )
46+
47+ fetcher
48+ . path ( '/bodyquery/{id}' )
49+ . method ( 'post' )
50+ // @ts -expect-error // Missing the optional param is wrong
51+ . create ( { scalar : 1 } )
52+
53+ fetcher
54+ . path ( '/bodyquery/{id}' )
55+ . method ( 'post' )
56+ . create ( { scalar : 1 , optional : 1 } )
57+
58+ expect ( true ) . toBe ( true )
59+ } )
60+
4361 it ( 'argument' , ( ) => {
4462 const same : Same < Openapi2 [ 'Argument' ] , Openapi3 [ 'Argument' ] > = true
4563 expect ( same ) . toBe ( true )
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export type Data = {
99type Query = {
1010 parameters : {
1111 path : { a : number ; b : string }
12- query : { scalar : string ; list : string [ ] }
12+ query : { scalar : string ; list : string [ ] ; optional ?: string }
1313 }
1414 responses : { 200 : { schema : Data } }
1515}
@@ -33,7 +33,7 @@ type BodyArray = {
3333type BodyAndQuery = {
3434 parameters : {
3535 path : { id : number }
36- query : { scalar : string }
36+ query : { scalar : string ; optional ?: string }
3737 body : { payload : { list : string [ ] } }
3838 }
3939 responses : { 201 : { schema : Data } }
You can’t perform that action at this time.
0 commit comments