@@ -2,7 +2,7 @@ import type {
2
2
DefinitionsFromApi ,
3
3
OverrideResultType ,
4
4
TagTypesFromApi ,
5
- } from '@internal /query/endpointDefinitions'
5
+ } from '@reduxjs/toolkit/dist /query/endpointDefinitions'
6
6
import { ANY , setupApiStore } from '@internal/tests/utils/helpers'
7
7
import type { SerializedError } from '@reduxjs/toolkit'
8
8
import { configureStore } from '@reduxjs/toolkit'
@@ -29,6 +29,7 @@ describe('type tests', () => {
29
29
} ) ,
30
30
} ) ,
31
31
} )
32
+
32
33
configureStore ( {
33
34
reducer : {
34
35
[ api . reducerPath ] : api . reducer ,
@@ -38,9 +39,8 @@ describe('type tests', () => {
38
39
39
40
expectTypeOf ( api . reducerPath ) . toEqualTypeOf < 'api' > ( )
40
41
41
- type TagTypes = typeof api extends Api < any , any , any , infer E >
42
- ? E
43
- : 'no match'
42
+ type TagTypes =
43
+ typeof api extends Api < any , any , any , infer E > ? E : 'no match'
44
44
45
45
assertType < TagTypes > ( ANY as never )
46
46
@@ -55,6 +55,7 @@ describe('type tests', () => {
55
55
endpoints : ( ) => ( { } ) ,
56
56
tagTypes : [ 'typeA' , 'typeB' ] ,
57
57
} )
58
+
58
59
test ( 'query: query & transformResponse types' , ( ) => {
59
60
api . injectEndpoints ( {
60
61
endpoints : ( build ) => ( {
@@ -121,6 +122,7 @@ describe('type tests', () => {
121
122
} ) ,
122
123
} )
123
124
} )
125
+
124
126
test ( 'mutation: query & transformResponse types' , ( ) => {
125
127
api . injectEndpoints ( {
126
128
endpoints : ( build ) => ( {
@@ -190,6 +192,7 @@ describe('type tests', () => {
190
192
191
193
describe ( 'enhancing endpoint definitions' , ( ) => {
192
194
const baseQuery = ( x : string ) => ( { data : 'success' } )
195
+
193
196
function getNewApi ( ) {
194
197
return createApi ( {
195
198
baseQuery,
@@ -206,15 +209,17 @@ describe('type tests', () => {
206
209
} ) ,
207
210
} )
208
211
}
209
- const api = getNewApi ( )
212
+
213
+ const api1 = getNewApi ( )
210
214
211
215
test ( 'warn on wrong tagType' , ( ) => {
212
- const storeRef = setupApiStore ( api , undefined , {
216
+ const storeRef = setupApiStore ( api1 , undefined , {
213
217
withoutTestLifecycles : true ,
214
218
} )
219
+
215
220
// only type-test this part
216
221
if ( 2 > 1 ) {
217
- api . enhanceEndpoints ( {
222
+ api1 . enhanceEndpoints ( {
218
223
endpoints : {
219
224
query1 : {
220
225
// @ts -expect-error
@@ -228,7 +233,7 @@ describe('type tests', () => {
228
233
} )
229
234
}
230
235
231
- const enhanced = api . enhanceEndpoints ( {
236
+ const enhanced = api1 . enhanceEndpoints ( {
232
237
addTagTypes : [ 'new' ] ,
233
238
endpoints : {
234
239
query1 : {
@@ -241,9 +246,9 @@ describe('type tests', () => {
241
246
} ,
242
247
} )
243
248
244
- storeRef . store . dispatch ( api . endpoints . query1 . initiate ( 'in1' ) )
249
+ storeRef . store . dispatch ( api1 . endpoints . query1 . initiate ( 'in1' ) )
245
250
246
- storeRef . store . dispatch ( api . endpoints . query2 . initiate ( 'in2' ) )
251
+ storeRef . store . dispatch ( api1 . endpoints . query2 . initiate ( 'in2' ) )
247
252
248
253
// only type-test this part
249
254
if ( 2 > 1 ) {
@@ -263,10 +268,11 @@ describe('type tests', () => {
263
268
} )
264
269
265
270
test ( 'modify' , ( ) => {
266
- const storeRef = setupApiStore ( api , undefined , {
271
+ const storeRef = setupApiStore ( api1 , undefined , {
267
272
withoutTestLifecycles : true ,
268
273
} )
269
- api . enhanceEndpoints ( {
274
+
275
+ api1 . enhanceEndpoints ( {
270
276
endpoints : {
271
277
query1 : {
272
278
query : ( x ) => {
@@ -301,10 +307,10 @@ describe('type tests', () => {
301
307
} ,
302
308
} )
303
309
304
- storeRef . store . dispatch ( api . endpoints . query1 . initiate ( 'in1' ) )
305
- storeRef . store . dispatch ( api . endpoints . query2 . initiate ( 'in2' ) )
306
- storeRef . store . dispatch ( api . endpoints . mutation1 . initiate ( 'in1' ) )
307
- storeRef . store . dispatch ( api . endpoints . mutation2 . initiate ( 'in2' ) )
310
+ storeRef . store . dispatch ( api1 . endpoints . query1 . initiate ( 'in1' ) )
311
+ storeRef . store . dispatch ( api1 . endpoints . query2 . initiate ( 'in2' ) )
312
+ storeRef . store . dispatch ( api1 . endpoints . mutation1 . initiate ( 'in1' ) )
313
+ storeRef . store . dispatch ( api1 . endpoints . mutation2 . initiate ( 'in2' ) )
308
314
} )
309
315
310
316
test ( 'updated transform response types' , async ( ) => {
@@ -319,13 +325,15 @@ describe('type tests', () => {
319
325
320
326
type Transformed = { value : string }
321
327
322
- type Definitions = DefinitionsFromApi < typeof api >
323
- type TagTypes = TagTypesFromApi < typeof api >
328
+ type Definitions = DefinitionsFromApi < typeof api1 >
329
+
330
+ type TagTypes = TagTypesFromApi < typeof api1 >
324
331
325
332
type Q1Definition = OverrideResultType <
326
333
Definitions [ 'query1' ] ,
327
334
Transformed
328
335
>
336
+
329
337
type M1Definition = OverrideResultType <
330
338
Definitions [ 'mutation1' ] ,
331
339
Transformed
@@ -359,15 +367,15 @@ describe('type tests', () => {
359
367
} )
360
368
361
369
const queryResponse = await storeRef . store . dispatch (
362
- enhancedApi . endpoints . query1 . initiate ( )
370
+ enhancedApi . endpoints . query1 . initiate ( ) ,
363
371
)
364
372
365
373
expectTypeOf ( queryResponse . data ) . toMatchTypeOf <
366
374
Transformed | undefined
367
375
> ( )
368
376
369
377
const mutationResponse = await storeRef . store . dispatch (
370
- enhancedApi . endpoints . mutation1 . initiate ( )
378
+ enhancedApi . endpoints . mutation1 . initiate ( ) ,
371
379
)
372
380
373
381
expectTypeOf ( mutationResponse ) . toMatchTypeOf <
0 commit comments