Skip to content

Commit 48ff17c

Browse files
committed
Fix problems related to the @typescript-eslint/array-type rule
1 parent 9e59d89 commit 48ff17c

16 files changed

+55
-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: 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
/**
@@ -339,12 +335,12 @@ export function buildSelectors<
339335

340336
function selectInvalidatedBy(
341337
state: RootState,
342-
tags: ReadonlyArray<TagDescription<string> | null | undefined>,
343-
): Array<{
338+
tags: readonly (TagDescription<string> | null | undefined)[],
339+
): {
344340
endpointName: string
345341
originalArgs: any
346342
queryCacheKey: QueryCacheKey
347-
}> {
343+
}[] {
348344
const apiState = state[reducerPath]
349345
const toInvalidate = new Set<QueryCacheKey>()
350346
for (const tag of tags.filter(isNotNullish).map(expandTagDescription)) {
@@ -386,7 +382,7 @@ export function buildSelectors<
386382
>(
387383
state: RootState,
388384
queryName: QueryName,
389-
): Array<QueryArgFromAnyQuery<Definitions[QueryName]>> {
385+
): QueryArgFromAnyQuery<Definitions[QueryName]>[] {
390386
return Object.values(selectQueries(state) as QueryState<any>)
391387
.filter(
392388
(

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

packages/toolkit/src/query/tsHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function assertCast<T>(v: any): asserts v is T {
1010

1111
export function safeAssign<T extends object>(
1212
target: T,
13-
...args: Array<Partial<NoInfer<T>>>
13+
...args: Partial<NoInfer<T>>[]
1414
): T {
1515
return Object.assign(target, ...args)
1616
}

0 commit comments

Comments
 (0)