1- import type { RetryOptions } from '@internal/query/retry'
1+ import { retry , type RetryOptions } from '@internal/query/retry'
2+ import {
3+ fetchBaseQuery ,
4+ type FetchBaseQueryError ,
5+ type FetchBaseQueryMeta ,
6+ } from '@internal/query/fetchBaseQuery'
27
38describe ( 'type tests' , ( ) => {
49 test ( 'RetryOptions only accepts one of maxRetries or retryCondition' , ( ) => {
@@ -14,6 +19,28 @@ describe('type tests', () => {
1419 retryCondition : ( ) => false ,
1520 } ) . not . toMatchTypeOf < RetryOptions > ( )
1621 } )
17- } )
22+ test ( 'fail can be pretyped to only accept correct error and meta' , ( ) => {
23+ expectTypeOf ( retry . fail ) . parameter ( 0 ) . toEqualTypeOf < unknown > ( )
24+ expectTypeOf ( retry . fail ) . parameter ( 1 ) . toEqualTypeOf < { } | undefined > ( )
25+ expectTypeOf ( retry . fail ) . toBeCallableWith ( 'Literally anything' , { } )
26+
27+ const myBaseQuery = fetchBaseQuery ( )
28+ const typedFail = retry . fail < typeof myBaseQuery >
29+
30+ expectTypeOf ( typedFail ) . parameter ( 0 ) . toMatchTypeOf < FetchBaseQueryError > ( )
31+ expectTypeOf ( typedFail )
32+ . parameter ( 1 )
33+ . toMatchTypeOf < FetchBaseQueryMeta | undefined > ( )
1834
19- export { }
35+ expectTypeOf ( typedFail ) . toBeCallableWith (
36+ {
37+ status : 401 ,
38+ data : 'Unauthorized' ,
39+ } ,
40+ { request : new Request ( 'http://localhost' ) } ,
41+ )
42+
43+ expectTypeOf ( typedFail ) . parameter ( 0 ) . not . toMatchTypeOf < string > ( )
44+ expectTypeOf ( typedFail ) . parameter ( 1 ) . not . toMatchTypeOf < { } > ( )
45+ } )
46+ } )
0 commit comments