@@ -85,6 +85,44 @@ describe("types", () => {
85
85
useQuery ( "/pet/findByStatus" , null ) ;
86
86
} ) ;
87
87
} ) ;
88
+
89
+ describe ( "rejects extra properties" , ( ) => {
90
+ it ( "in query params" , ( ) => {
91
+ useQuery ( "/pet/findByStatus" , {
92
+ params : {
93
+ query : {
94
+ status : "available" ,
95
+ // @ts -expect-error extra property should be rejected
96
+ invalid_property : "nope" ,
97
+ } ,
98
+ } ,
99
+ } ) ;
100
+ } ) ;
101
+
102
+ it ( "in path params" , ( ) => {
103
+ useQuery ( "/pet/{petId}" , {
104
+ params : {
105
+ path : {
106
+ petId : 5 ,
107
+ // @ts -expect-error extra property should be rejected
108
+ invalid_path_param : "nope" ,
109
+ } ,
110
+ } ,
111
+ } ) ;
112
+ } ) ;
113
+
114
+ it ( "in header params" , ( ) => {
115
+ useQuery ( "/pet/findByStatus" , {
116
+ params : {
117
+ header : {
118
+ "X-Example" : "test" ,
119
+ // @ts -expect-error extra property should be rejected
120
+ "Invalid-Header" : "nope" ,
121
+ } ,
122
+ } ,
123
+ } ) ;
124
+ } ) ;
125
+ } ) ;
88
126
} ) ;
89
127
90
128
describe ( "useImmutable" , ( ) => {
@@ -122,6 +160,44 @@ describe("types", () => {
122
160
useImmutable ( "/pet/findByStatus" , null ) ;
123
161
} ) ;
124
162
} ) ;
163
+
164
+ describe ( "rejects extra properties" , ( ) => {
165
+ it ( "in query params" , ( ) => {
166
+ useImmutable ( "/pet/findByStatus" , {
167
+ params : {
168
+ query : {
169
+ status : "available" ,
170
+ // @ts -expect-error extra property should be rejected
171
+ invalid_property : "nope" ,
172
+ } ,
173
+ } ,
174
+ } ) ;
175
+ } ) ;
176
+
177
+ it ( "in path params" , ( ) => {
178
+ useImmutable ( "/pet/{petId}" , {
179
+ params : {
180
+ path : {
181
+ petId : 5 ,
182
+ // @ts -expect-error extra property should be rejected
183
+ invalid_path_param : "nope" ,
184
+ } ,
185
+ } ,
186
+ } ) ;
187
+ } ) ;
188
+
189
+ it ( "in header params" , ( ) => {
190
+ useImmutable ( "/pet/findByStatus" , {
191
+ params : {
192
+ header : {
193
+ "X-Example" : "test" ,
194
+ // @ts -expect-error extra property should be rejected
195
+ "Invalid-Header" : "nope" ,
196
+ } ,
197
+ } ,
198
+ } ) ;
199
+ } ) ;
200
+ } ) ;
125
201
} ) ;
126
202
127
203
describe ( "useInfinite" , ( ) => {
@@ -154,40 +230,47 @@ describe("types", () => {
154
230
useInfinite ( "/pet/findByStatus" , ( ) => null ) ;
155
231
} ) ;
156
232
} ) ;
157
- } ) ;
158
233
159
- describe ( "useMutate -> mutate" , ( ) => {
160
- it ( "accepts path alone" , async ( ) => {
161
- await mutate ( [ "/pet/{petId}" ] ) ;
162
- } ) ;
234
+ describe ( "rejects extra properties" , ( ) => {
235
+ it ( "in query params" , ( ) => {
236
+ useInfinite ( "/pet/findByStatus" , ( ) => ( {
237
+ params : {
238
+ query : {
239
+ status : "available" ,
240
+ // @ts -expect-error extra property should be rejected
241
+ invalid_property : "nope" ,
242
+ } ,
243
+ } ,
244
+ } ) ) ;
245
+ } ) ;
163
246
164
- it ( "accepts path and init" , async ( ) => {
165
- await mutate ( [
166
- "/pet/{petId}" ,
167
- {
247
+ it ( "in path params" , ( ) => {
248
+ useInfinite ( "/pet/{petId}" , ( ) => ( {
168
249
params : {
169
250
path : {
170
251
petId : 5 ,
252
+ // @ts -expect-error extra property should be rejected
253
+ invalid_path_param : "nope" ,
171
254
} ,
172
255
} ,
173
- } ,
174
- ] ) ;
175
- } ) ;
176
-
177
- it ( "accepts partial init" , async ( ) => {
178
- await mutate ( [ "/pet/{petId}" , { params : { } } ] ) ;
179
- } ) ;
256
+ } ) ) ;
257
+ } ) ;
180
258
181
- it ( "does not accept `null` init" , async ( ) => {
182
- await mutate ( [
183
- "/pet/{petId}" ,
184
- // @ts -expect-error null not accepted
185
- null ,
186
- ] ) ;
259
+ it ( "in header params" , ( ) => {
260
+ useInfinite ( "/pet/findByStatus" , ( ) => ( {
261
+ params : {
262
+ header : {
263
+ "X-Example" : "test" ,
264
+ // @ts -expect-error extra property should be rejected
265
+ "Invalid-Header" : "nope" ,
266
+ } ,
267
+ } ,
268
+ } ) ) ;
269
+ } ) ;
187
270
} ) ;
188
271
} ) ;
189
272
190
- describe ( "when init is not required " , ( ) => {
273
+ describe ( "useMutate -> mutate " , ( ) => {
191
274
it ( "accepts path alone" , async ( ) => {
192
275
await mutate ( [ "/pet/{petId}" ] ) ;
193
276
} ) ;
@@ -216,6 +299,84 @@ describe("types", () => {
216
299
null ,
217
300
] ) ;
218
301
} ) ;
302
+
303
+ describe ( "when init is not required" , ( ) => {
304
+ it ( "accepts path alone" , async ( ) => {
305
+ await mutate ( [ "/pet/{petId}" ] ) ;
306
+ } ) ;
307
+
308
+ it ( "accepts path and init" , async ( ) => {
309
+ await mutate ( [
310
+ "/pet/{petId}" ,
311
+ {
312
+ params : {
313
+ path : {
314
+ petId : 5 ,
315
+ } ,
316
+ } ,
317
+ } ,
318
+ ] ) ;
319
+ } ) ;
320
+
321
+ it ( "accepts partial init" , async ( ) => {
322
+ await mutate ( [ "/pet/{petId}" , { params : { } } ] ) ;
323
+ } ) ;
324
+
325
+ it ( "does not accept `null` init" , async ( ) => {
326
+ await mutate ( [
327
+ "/pet/{petId}" ,
328
+ // @ts -expect-error null not accepted
329
+ null ,
330
+ ] ) ;
331
+ } ) ;
332
+ } ) ;
333
+
334
+ describe ( "rejects extra properties" , ( ) => {
335
+ it ( "in path" , ( ) => {
336
+ mutate ( [
337
+ "/pet/{petId}" ,
338
+ {
339
+ params : {
340
+ path : {
341
+ petId : 5 ,
342
+ // @ts -expect-error extra property should be rejected
343
+ invalid_path_param : "no" ,
344
+ } ,
345
+ } ,
346
+ } ,
347
+ ] ) ;
348
+ } ) ;
349
+
350
+ it ( "in query params" , ( ) => {
351
+ mutate ( [
352
+ "/pet/findByStatus" ,
353
+ {
354
+ params : {
355
+ query : {
356
+ status : "available" ,
357
+ // @ts -expect-error extra property should be rejected
358
+ invalid_property : "nope" ,
359
+ } ,
360
+ } ,
361
+ } ,
362
+ ] ) ;
363
+ } ) ;
364
+
365
+ it ( "in header params" , ( ) => {
366
+ mutate ( [
367
+ "/pet/findByStatus" ,
368
+ {
369
+ params : {
370
+ header : {
371
+ "X-Example" : "test" ,
372
+ // @ts -expect-error extra property should be rejected
373
+ "Invalid-Header" : "nope" ,
374
+ } ,
375
+ } ,
376
+ } ,
377
+ ] ) ;
378
+ } ) ;
379
+ } ) ;
219
380
} ) ;
220
381
} ) ;
221
382
0 commit comments