Skip to content

Commit 7713856

Browse files
committed
Fix issue with importing endpointDefinitions inside createApi.test-d.ts
1 parent 18a6b2a commit 7713856

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

packages/toolkit/src/query/tests/createApi.test-d.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {
22
DefinitionsFromApi,
33
OverrideResultType,
44
TagTypesFromApi,
5-
} from '@internal/query/endpointDefinitions'
5+
} from '@reduxjs/toolkit/dist/query/endpointDefinitions'
66
import { ANY, setupApiStore } from '@internal/tests/utils/helpers'
77
import type { SerializedError } from '@reduxjs/toolkit'
88
import { configureStore } from '@reduxjs/toolkit'
@@ -29,6 +29,7 @@ describe('type tests', () => {
2929
}),
3030
}),
3131
})
32+
3233
configureStore({
3334
reducer: {
3435
[api.reducerPath]: api.reducer,
@@ -38,9 +39,8 @@ describe('type tests', () => {
3839

3940
expectTypeOf(api.reducerPath).toEqualTypeOf<'api'>()
4041

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'
4444

4545
assertType<TagTypes>(ANY as never)
4646

@@ -55,6 +55,7 @@ describe('type tests', () => {
5555
endpoints: () => ({}),
5656
tagTypes: ['typeA', 'typeB'],
5757
})
58+
5859
test('query: query & transformResponse types', () => {
5960
api.injectEndpoints({
6061
endpoints: (build) => ({
@@ -121,6 +122,7 @@ describe('type tests', () => {
121122
}),
122123
})
123124
})
125+
124126
test('mutation: query & transformResponse types', () => {
125127
api.injectEndpoints({
126128
endpoints: (build) => ({
@@ -190,6 +192,7 @@ describe('type tests', () => {
190192

191193
describe('enhancing endpoint definitions', () => {
192194
const baseQuery = (x: string) => ({ data: 'success' })
195+
193196
function getNewApi() {
194197
return createApi({
195198
baseQuery,
@@ -206,15 +209,17 @@ describe('type tests', () => {
206209
}),
207210
})
208211
}
209-
const api = getNewApi()
212+
213+
const api1 = getNewApi()
210214

211215
test('warn on wrong tagType', () => {
212-
const storeRef = setupApiStore(api, undefined, {
216+
const storeRef = setupApiStore(api1, undefined, {
213217
withoutTestLifecycles: true,
214218
})
219+
215220
// only type-test this part
216221
if (2 > 1) {
217-
api.enhanceEndpoints({
222+
api1.enhanceEndpoints({
218223
endpoints: {
219224
query1: {
220225
// @ts-expect-error
@@ -228,7 +233,7 @@ describe('type tests', () => {
228233
})
229234
}
230235

231-
const enhanced = api.enhanceEndpoints({
236+
const enhanced = api1.enhanceEndpoints({
232237
addTagTypes: ['new'],
233238
endpoints: {
234239
query1: {
@@ -241,9 +246,9 @@ describe('type tests', () => {
241246
},
242247
})
243248

244-
storeRef.store.dispatch(api.endpoints.query1.initiate('in1'))
249+
storeRef.store.dispatch(api1.endpoints.query1.initiate('in1'))
245250

246-
storeRef.store.dispatch(api.endpoints.query2.initiate('in2'))
251+
storeRef.store.dispatch(api1.endpoints.query2.initiate('in2'))
247252

248253
// only type-test this part
249254
if (2 > 1) {
@@ -263,10 +268,11 @@ describe('type tests', () => {
263268
})
264269

265270
test('modify', () => {
266-
const storeRef = setupApiStore(api, undefined, {
271+
const storeRef = setupApiStore(api1, undefined, {
267272
withoutTestLifecycles: true,
268273
})
269-
api.enhanceEndpoints({
274+
275+
api1.enhanceEndpoints({
270276
endpoints: {
271277
query1: {
272278
query: (x) => {
@@ -301,10 +307,10 @@ describe('type tests', () => {
301307
},
302308
})
303309

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'))
308314
})
309315

310316
test('updated transform response types', async () => {
@@ -319,13 +325,15 @@ describe('type tests', () => {
319325

320326
type Transformed = { value: string }
321327

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>
324331

325332
type Q1Definition = OverrideResultType<
326333
Definitions['query1'],
327334
Transformed
328335
>
336+
329337
type M1Definition = OverrideResultType<
330338
Definitions['mutation1'],
331339
Transformed
@@ -359,15 +367,15 @@ describe('type tests', () => {
359367
})
360368

361369
const queryResponse = await storeRef.store.dispatch(
362-
enhancedApi.endpoints.query1.initiate()
370+
enhancedApi.endpoints.query1.initiate(),
363371
)
364372

365373
expectTypeOf(queryResponse.data).toMatchTypeOf<
366374
Transformed | undefined
367375
>()
368376

369377
const mutationResponse = await storeRef.store.dispatch(
370-
enhancedApi.endpoints.mutation1.initiate()
378+
enhancedApi.endpoints.mutation1.initiate(),
371379
)
372380

373381
expectTypeOf(mutationResponse).toMatchTypeOf<

0 commit comments

Comments
 (0)