@@ -336,6 +336,52 @@ describe("types", () => {
336336 } ) ;
337337 } ) ;
338338 } ) ;
339+
340+ describe ( "custom error types" , ( ) => {
341+ const uniqueKey = "<unique-key>" ;
342+ type Key = typeof uniqueKey ;
343+ const useQuery = createQueryHook < paths , `${string } /${string } `, Key , Error > ( client , uniqueKey ) ;
344+ const useImmutable = createImmutableHook < paths , `${string } /${string } `, Key , Error > ( client , uniqueKey ) ;
345+ const useInfinite = createInfiniteHook < paths , `${string } /${string } `, Key , Error > ( client , uniqueKey ) ;
346+
347+ describe ( "useQuery" , ( ) => {
348+ it ( "returns correct error" , ( ) => {
349+ const { error } = useQuery ( "/pet/{petId}" , {
350+ params : {
351+ path : {
352+ petId : 5 ,
353+ } ,
354+ } ,
355+ } ) ;
356+
357+ expectTypeOf ( error ) . toEqualTypeOf < PetInvalid | Error | undefined > ( ) ;
358+ } ) ;
359+ } ) ;
360+
361+ describe ( "useImmutable" , ( ) => {
362+ it ( "returns correct error" , ( ) => {
363+ const { error } = useImmutable ( "/pet/{petId}" , {
364+ params : {
365+ path : {
366+ petId : 5 ,
367+ } ,
368+ } ,
369+ } ) ;
370+
371+ expectTypeOf ( error ) . toEqualTypeOf < PetInvalid | Error | undefined > ( ) ;
372+ } ) ;
373+ } ) ;
374+
375+ describe ( "useInfinite" , ( ) => {
376+ it ( "returns correct error" , ( ) => {
377+ const { error } = useInfinite ( "/pet/findByStatus" , ( _index , _prev ) => ( {
378+ params : { query : { status : "available" } } ,
379+ } ) ) ;
380+
381+ expectTypeOf ( error ) . toEqualTypeOf < PetStatusInvalid | Error | undefined > ( ) ;
382+ } ) ;
383+ } ) ;
384+ } ) ;
339385} ) ;
340386
341387describe ( "TypesForRequest" , ( ) => {
0 commit comments