Skip to content

Commit 43c69be

Browse files
committed
Fix problems related to the @typescript-eslint/array-type rule
1 parent f73a646 commit 43c69be

17 files changed

+67
-58
lines changed

packages/toolkit/src/combineSlices.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ type SliceLikeReducerPath<A extends AnySliceLike> =
2323
type SliceLikeState<A extends AnySliceLike> =
2424
A extends SliceLike<any, infer State> ? State : never
2525

26-
export type WithSlice<A extends AnySliceLike> = {
27-
[Path in SliceLikeReducerPath<A>]: SliceLikeState<A>
28-
}
26+
export type WithSlice<A extends AnySliceLike> = Record<
27+
SliceLikeReducerPath<A>,
28+
SliceLikeState<A>
29+
>
2930

3031
type ReducerMap = Record<string, Reducer>
3132

@@ -292,7 +293,7 @@ export interface CombinedSliceReducer<
292293
}
293294
}
294295

295-
type InitialState<Slices extends Array<AnySliceLike | ReducerMap>> =
296+
type InitialState<Slices extends (AnySliceLike | ReducerMap)[]> =
296297
UnionToIntersection<
297298
Slices[number] extends infer Slice
298299
? Slice extends AnySliceLike
@@ -307,7 +308,7 @@ const isSliceLike = (
307308
'reducerPath' in maybeSliceLike &&
308309
typeof maybeSliceLike.reducerPath === 'string'
309310

310-
const getReducers = (slices: Array<AnySliceLike | ReducerMap>) =>
311+
const getReducers = (slices: (AnySliceLike | ReducerMap)[]) =>
311312
slices.flatMap((sliceOrMap) =>
312313
isSliceLike(sliceOrMap)
313314
? [[sliceOrMap.reducerPath, sliceOrMap.reducer] as const]
@@ -363,7 +364,7 @@ const original = (state: any) => {
363364

364365
const noopReducer: Reducer<Record<string, any>> = (state = {}) => state
365366

366-
export function combineSlices<Slices extends Array<AnySliceLike | ReducerMap>>(
367+
export function combineSlices<Slices extends (AnySliceLike | ReducerMap)[]>(
367368
...slices: Slices
368369
): CombinedSliceReducer<Id<InitialState<Slices>>> {
369370
const reducerMap = Object.fromEntries<Reducer>(getReducers(slices))

packages/toolkit/src/configureStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ export interface ConfigureStoreOptions<
8888
enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E
8989
}
9090

91-
export type Middlewares<S> = ReadonlyArray<Middleware<AnyNonNullishValue, S>>
91+
export type Middlewares<S> = readonly Middleware<AnyNonNullishValue, S>[]
9292

93-
type Enhancers = ReadonlyArray<StoreEnhancer>
93+
type Enhancers = readonly StoreEnhancer[]
9494

9595
/**
9696
* A Redux store returned by `configureStore()`. Supports dispatching

packages/toolkit/src/createReducer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ export type ActionMatcherDescription<S, A extends Action> = {
2121
reducer: CaseReducer<S, NoInfer<A>>
2222
}
2323

24-
export type ReadonlyActionMatcherDescriptionCollection<S> = ReadonlyArray<
25-
ActionMatcherDescription<S, any>
26-
>
24+
export type ReadonlyActionMatcherDescriptionCollection<S> =
25+
readonly ActionMatcherDescription<S, any>[]
2726

28-
export type ActionMatcherDescriptionCollection<S> = Array<
29-
ActionMatcherDescription<S, any>
30-
>
27+
export type ActionMatcherDescriptionCollection<S> = ActionMatcherDescription<
28+
S,
29+
any
30+
>[]
3131

3232
/**
3333
* A *case reducer* is a reducer function for a specific action type. Case

packages/toolkit/src/entities/models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ export interface EntityStateAdapter<T, Id extends EntityId> {
129129

130130
updateMany<S extends DraftableEntityState<T, Id>>(
131131
state: PreventAny<S, T, Id>,
132-
updates: ReadonlyArray<Update<T, Id>>,
132+
updates: readonly Update<T, Id>[],
133133
): S
134134
updateMany<S extends DraftableEntityState<T, Id>>(
135135
state: PreventAny<S, T, Id>,
136-
updates: PayloadAction<ReadonlyArray<Update<T, Id>>>,
136+
updates: PayloadAction<readonly Update<T, Id>[]>,
137137
): S
138138

139139
upsertOne<S extends DraftableEntityState<T, Id>>(

packages/toolkit/src/entities/sorted_state_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function createSortedStateAdapter<T, Id extends EntityId>(
113113
}
114114

115115
function updateManyMutably(
116-
updates: ReadonlyArray<Update<T, Id>>,
116+
updates: readonly Update<T, Id>[],
117117
state: R,
118118
): void {
119119
let appliedUpdates = false

packages/toolkit/src/entities/unsorted_state_adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function createUnsortedStateAdapter<T, Id extends EntityId>(
102102
}
103103

104104
function takeNewKey(
105-
keys: Record<string, Id>,
105+
keys: Record<EntityId, Id>,
106106
update: Update<T, Id>,
107107
state: R,
108108
): boolean {
@@ -132,9 +132,9 @@ export function createUnsortedStateAdapter<T, Id extends EntityId>(
132132
updates: readonly Update<T, Id>[],
133133
state: R,
134134
): void {
135-
const newKeys: Record<string, Id> = {}
135+
const newKeys: Record<EntityId, Id> = {}
136136

137-
const updatesPerEntity: Record<string, Update<T, Id>> = {}
137+
const updatesPerEntity: Record<EntityId, Update<T, Id>> = {}
138138

139139
updates.forEach((update) => {
140140
// Only apply updates to entities that currently exist

packages/toolkit/src/query/core/buildSelectors.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import type {
2727
} from './apiState'
2828
import { QueryStatus, getRequestStatusFlags } from './apiState'
2929
import { getMutationCacheKey } from './buildSlice'
30+
import { getNextPageParam, getPreviousPageParam } from './buildThunks'
3031
import type { createSelector as _createSelector } from './rtkImports'
3132
import { createNextState } from './rtkImports'
32-
import { getNextPageParam, getPreviousPageParam } from './buildThunks'
3333

3434
export type SkipToken = typeof skipToken
3535
/**
@@ -334,12 +334,12 @@ export function buildSelectors<
334334

335335
function selectInvalidatedBy(
336336
state: RootState,
337-
tags: ReadonlyArray<TagDescription<string> | null | undefined>,
338-
): Array<{
337+
tags: readonly (TagDescription<string> | null | undefined)[],
338+
): {
339339
endpointName: string
340340
originalArgs: any
341341
queryCacheKey: QueryCacheKey
342-
}> {
342+
}[] {
343343
const apiState = state[reducerPath]
344344
const toInvalidate = new Set<QueryCacheKey>()
345345
for (const tag of tags.filter(isNotNullish).map(expandTagDescription)) {
@@ -379,7 +379,7 @@ export function buildSelectors<
379379
function selectCachedArgsForQuery<QueryName extends QueryKeys<Definitions>>(
380380
state: RootState,
381381
queryName: QueryName,
382-
): Array<QueryArgFrom<Definitions[QueryName]>> {
382+
): QueryArgFrom<Definitions[QueryName]>[] {
383383
return Object.values(selectQueries(state) as QueryState<any>)
384384
.filter(
385385
(

packages/toolkit/src/query/core/buildSlice.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ import type {
77
AssertTagTypes,
88
EndpointDefinitions,
99
FullTagDescription,
10-
QueryArgFrom,
1110
QueryDefinition,
12-
ResultTypeFrom,
1311
} from '../endpointDefinitions'
12+
import { isInfiniteQueryDefinition } from '../endpointDefinitions'
1413
import {
1514
copyWithStructuralSharing,
1615
isDocumentVisible,
1716
isOnline,
1817
} from '../utils'
1918
import type {
2019
ConfigState,
20+
InfiniteQueryDirection,
21+
InfiniteQuerySubState,
2122
InvalidationState,
2223
MutationState,
2324
MutationSubState,
2425
MutationSubstateIdentifier,
2526
QueryCacheKey,
26-
QueryKeys,
2727
QueryState,
2828
QuerySubState,
2929
QuerySubstateIdentifier,
@@ -32,7 +32,15 @@ import type {
3232
} from './apiState'
3333
import { QueryStatus } from './apiState'
3434
import { isUpsertQuery } from './buildInitiate'
35-
import type { MutationThunk, QueryThunk, QueryThunkArg } from './buildThunks'
35+
import type {
36+
AllQueryKeys,
37+
DataFromAnyQueryDefinition,
38+
InfiniteQueryThunk,
39+
MutationThunk,
40+
QueryArgFromAnyQueryDefinition,
41+
QueryThunk,
42+
QueryThunkArg,
43+
} from './buildThunks'
3644
import { calculateProvidedByThunk } from './buildThunks'
3745
import {
3846
SHOULD_AUTOBATCH,
@@ -78,7 +86,7 @@ export type ProcessedQueryUpsertEntry = {
7886
* A typesafe representation of a util action creator that accepts cache entry descriptions to upsert
7987
*/
8088
export type UpsertEntries<Definitions extends EndpointDefinitions> = (<
81-
EndpointNames extends Array<AllQueryKeys<Definitions>>,
89+
EndpointNames extends AllQueryKeys<Definitions>[],
8290
>(
8391
entries: [
8492
...{

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export type GetResultDescriptionFn<
234234
error: ErrorType | undefined,
235235
arg: QueryArg,
236236
meta: MetaType,
237-
) => ReadonlyArray<TagDescription<TagTypes> | undefined | null>
237+
) => readonly (TagDescription<TagTypes> | undefined | null)[]
238238

239239
export type FullTagDescription<TagType> = {
240240
type: TagType
@@ -252,7 +252,7 @@ export type ResultDescription<
252252
ErrorType,
253253
MetaType,
254254
> =
255-
| ReadonlyArray<TagDescription<TagTypes> | undefined | null>
255+
| readonly (TagDescription<TagTypes> | undefined | null)[]
256256
| GetResultDescriptionFn<TagTypes, ResultType, QueryArg, ErrorType, MetaType>
257257

258258
type QueryTypes<

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('type tests', () => {
1111
completed: boolean
1212
}
1313

14-
type Todos = Array<Todo>
14+
type Todos = Todo[]
1515

1616
const exampleApi = createApi({
1717
reducerPath: 'api',
@@ -62,7 +62,7 @@ describe('type tests', () => {
6262
completed: boolean
6363
}
6464

65-
type Todos = Array<Todo>
65+
type Todos = Todo[]
6666

6767
const exampleApi = createApi({
6868
reducerPath: 'api',

0 commit comments

Comments
 (0)