@@ -128,10 +128,8 @@ describe('initialData', () => {
128
128
} )
129
129
130
130
describe ( 'TData type inference' , ( ) => {
131
-
132
131
it ( 'no inference of TData from return annotations' , ( ) => {
133
-
134
- const _testFn = ( ) : UseQueryResult < string , unknown > => {
132
+ const _testFn = ( ) : UseQueryResult < string , unknown > => {
135
133
// @ts -expect-error expect number to be un-assignable to string
136
134
return useQuery ( {
137
135
queryKey : [ ] ,
@@ -147,39 +145,37 @@ describe('initialData', () => {
147
145
} )
148
146
149
147
it ( 'correct or superset type annotations produce no type errors' , ( ) => {
150
-
151
- const _testFn = ( ) : UseQueryResult < number | string , unknown > => {
148
+ const _testFn = ( ) : UseQueryResult < number | string , unknown > => {
152
149
return useQuery ( {
153
150
queryKey : [ ] ,
154
151
queryFn : ( ) => 5 ,
155
152
} )
156
153
}
157
154
158
- expectTypeOf ( _testFn ( ) [ " data" ] ) . toEqualTypeOf < string | number > ( )
155
+ expectTypeOf ( _testFn ( ) [ ' data' ] ) . toEqualTypeOf < string | number > ( )
159
156
160
157
const _val : UseQueryResult < string | number , unknown > = useQuery ( {
161
158
queryKey : [ ] ,
162
159
queryFn : ( ) => 5 ,
163
160
} )
164
161
165
- expectTypeOf ( _val [ " data" ] ) . toEqualTypeOf < string | number | undefined > ( )
162
+ expectTypeOf ( _val [ ' data' ] ) . toEqualTypeOf < string | number | undefined > ( )
166
163
} )
167
164
168
165
it ( 'usage of select function still changes generic inference' , ( ) => {
169
-
170
166
const result = useQuery ( {
171
167
queryKey : [ ] ,
172
168
queryFn : ( ) => 5 ,
173
- select : ( ) => " foo"
169
+ select : ( ) => ' foo' ,
174
170
} )
175
171
176
- expectTypeOf ( result [ " data" ] ) . toEqualTypeOf < string | undefined > ( )
172
+ expectTypeOf ( result [ ' data' ] ) . toEqualTypeOf < string | undefined > ( )
177
173
178
174
const _result2 = useQuery < number , unknown , string , unknown [ ] > ( {
179
175
queryKey : [ ] ,
180
176
queryFn : ( ) => 5 ,
181
177
// @ts -expect-error select fn differs from generic (when provided), so correctly type errors)
182
- select : ( ) => 5
178
+ select : ( ) => 5 ,
183
179
} )
184
180
} )
185
181
} )
0 commit comments