Skip to content

Commit 9435d23

Browse files
committed
Fix problems related to the @typescript-eslint/array-type rule
1 parent 670c376 commit 9435d23

17 files changed

+62
-63
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]
@@ -368,7 +369,7 @@ const original = (state: any) => {
368369
const emptyObject = {}
369370
const noopReducer: Reducer<Record<string, any>> = (state = emptyObject) => state
370371

371-
export function combineSlices<Slices extends Array<AnySliceLike | ReducerMap>>(
372+
export function combineSlices<Slices extends (AnySliceLike | ReducerMap)[]>(
372373
...slices: Slices
373374
): CombinedSliceReducer<Id<InitialState<Slices>>> {
374375
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
@@ -93,9 +93,9 @@ export interface ConfigureStoreOptions<
9393
enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E
9494
}
9595

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

98-
type Enhancers = ReadonlyArray<StoreEnhancer>
98+
type Enhancers = readonly StoreEnhancer[]
9999

100100
/**
101101
* 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/apiState.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export type InfiniteQueryConfigOptions<DataType, PageParam, QueryArg> = {
4343
*/
4444
getNextPageParam: (
4545
lastPage: DataType,
46-
allPages: Array<DataType>,
46+
allPages: DataType[],
4747
lastPageParam: PageParam,
48-
allPageParams: Array<PageParam>,
48+
allPageParams: PageParam[],
4949
queryArg: QueryArg,
5050
) => PageParam | undefined | null
5151
/**
@@ -54,9 +54,9 @@ export type InfiniteQueryConfigOptions<DataType, PageParam, QueryArg> = {
5454
*/
5555
getPreviousPageParam?: (
5656
firstPage: DataType,
57-
allPages: Array<DataType>,
57+
allPages: DataType[],
5858
firstPageParam: PageParam,
59-
allPageParams: Array<PageParam>,
59+
allPageParams: PageParam[],
6060
queryArg: QueryArg,
6161
) => PageParam | undefined | null
6262
/**

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,17 @@ import type {
2020
InfiniteQuerySubState,
2121
MutationSubState,
2222
QueryCacheKey,
23-
QueryKeys,
2423
QueryState,
2524
QuerySubState,
2625
RequestStatusFlags,
2726
RootState as _RootState,
2827
} from './apiState'
2928
import { QueryStatus, getRequestStatusFlags } from './apiState'
3029
import { getMutationCacheKey } from './buildSlice'
30+
import type { AllQueryKeys } from './buildThunks'
31+
import { getNextPageParam, getPreviousPageParam } from './buildThunks'
3132
import type { createSelector as _createSelector } from './rtkImports'
3233
import { createNextState } from './rtkImports'
33-
import {
34-
type AllQueryKeys,
35-
getNextPageParam,
36-
getPreviousPageParam,
37-
} from './buildThunks'
3834

3935
export type SkipToken = typeof skipToken
4036
/**
@@ -338,12 +334,12 @@ export function buildSelectors<
338334

339335
function selectInvalidatedBy(
340336
state: RootState,
341-
tags: ReadonlyArray<TagDescription<string> | null | undefined>,
342-
): Array<{
337+
tags: readonly (TagDescription<string> | null | undefined)[],
338+
): {
343339
endpointName: string
344340
originalArgs: any
345341
queryCacheKey: QueryCacheKey
346-
}> {
342+
}[] {
347343
const apiState = state[reducerPath]
348344
const toInvalidate = new Set<QueryCacheKey>()
349345
for (const tag of tags.filter(isNotNullish).map(expandTagDescription)) {
@@ -385,7 +381,7 @@ export function buildSelectors<
385381
>(
386382
state: RootState,
387383
queryName: QueryName,
388-
): Array<QueryArgFromAnyQuery<Definitions[QueryName]>> {
384+
): QueryArgFromAnyQuery<Definitions[QueryName]>[] {
389385
return Object.values(selectQueries(state) as QueryState<any>)
390386
.filter(
391387
(

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,11 @@ export enum DefinitionType {
478478
infinitequery = 'infinitequery',
479479
}
480480

481-
type TagDescriptionArray<TagTypes extends string> = ReadonlyArray<
482-
TagDescription<TagTypes> | undefined | null
483-
>
481+
type TagDescriptionArray<TagTypes extends string> = readonly (
482+
| TagDescription<TagTypes>
483+
| undefined
484+
| null
485+
)[]
484486

485487
export type GetResultDescriptionFn<
486488
TagTypes extends string,

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)