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]
123
123
124
124
export type CreateFetch < M , OP > = M extends 'post' | 'put' | 'patch' | 'delete'
125
125
? OP extends { parameters : { query : infer Q } }
126
- ? _CreateFetch < OP , { [ K in keyof Q ] : true | 1 } >
126
+ ? _CreateFetch < OP , { [ K in keyof Q ] -? : true | 1 } >
127
127
: _CreateFetch < OP >
128
128
: _CreateFetch < OP >
129
129
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ describe('fetch', () => {
86
86
const fun = fetcher
87
87
. path ( '/bodyquery/{id}' )
88
88
. method ( method )
89
- . create ( { scalar : 1 } )
89
+ . create ( { scalar : 1 , optional : 1 } )
90
90
91
91
const { data } = await fun ( {
92
92
id : 1 ,
@@ -235,7 +235,7 @@ describe('fetch', () => {
235
235
const fun = fetcher
236
236
. path ( '/bodyquery/{id}' )
237
237
. method ( 'post' )
238
- . create ( { scalar : 1 } )
238
+ . create ( { scalar : 1 , optional : 1 } )
239
239
240
240
const captured = { url : '' , body : '' }
241
241
Original file line number Diff line number Diff line change 9
9
OpReturnType ,
10
10
TypedFetch ,
11
11
} from '../src'
12
+ import { paths } from './paths'
12
13
import { paths as paths2 } from './examples/stripe-openapi2'
13
14
import { paths as paths3 } from './examples/stripe-openapi3'
14
15
@@ -40,6 +41,23 @@ interface Openapi3 {
40
41
type Same < A , B > = A extends B ? ( B extends A ? true : false ) : false
41
42
42
43
describe ( '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
+
43
61
it ( 'argument' , ( ) => {
44
62
const same : Same < Openapi2 [ 'Argument' ] , Openapi3 [ 'Argument' ] > = true
45
63
expect ( same ) . toBe ( true )
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export type Data = {
9
9
type Query = {
10
10
parameters : {
11
11
path : { a : number ; b : string }
12
- query : { scalar : string ; list : string [ ] }
12
+ query : { scalar : string ; list : string [ ] ; optional ?: string }
13
13
}
14
14
responses : { 200 : { schema : Data } }
15
15
}
@@ -33,7 +33,7 @@ type BodyArray = {
33
33
type BodyAndQuery = {
34
34
parameters : {
35
35
path : { id : number }
36
- query : { scalar : string }
36
+ query : { scalar : string ; optional ?: string }
37
37
body : { payload : { list : string [ ] } }
38
38
}
39
39
responses : { 201 : { schema : Data } }
You can’t perform that action at this time.
0 commit comments