Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9b6b9de
Add `configs` to `workspaces`
aryaemami59 Aug 27, 2024
7781664
use foreach so publish doesn't fail if package doesn't have tests, an…
EskiMojo14 Feb 8, 2024
b6e81dc
Build `config` packages on `postinstall`
aryaemami59 Aug 27, 2024
260f923
Initialize all the `config` packages
aryaemami59 Aug 27, 2024
a7586d3
Use the shareable Prettier config
aryaemami59 Aug 27, 2024
3f14e4a
Use the shareable ESLint config
aryaemami59 Aug 27, 2024
cc7230b
Use shareable `tsconfig.json` files
aryaemami59 Aug 28, 2024
0d71b78
Use the shareable Vitest config
aryaemami59 Aug 28, 2024
dca79bc
Run `yarn format` to format all files
aryaemami59 Sep 3, 2024
6ce8871
Add `AnyNonNullishValue` helper type
aryaemami59 Sep 3, 2024
275c2e0
Add `AnyFunction` helper type
aryaemami59 Sep 3, 2024
5b9b778
Add `EmptyObject` helper type
aryaemami59 Sep 3, 2024
718d0d2
Add `AnyObject` helper type
aryaemami59 Sep 3, 2024
e70c337
Add `isObject` and `hasBodyAndHeaders` utility functions
aryaemami59 Sep 3, 2024
a69e82c
Change all `let` variables to `const` to comply with `prefer-const` rule
aryaemami59 Sep 3, 2024
dc41266
Make `hasBodyAndHeaders` assertion looser
aryaemami59 Sep 3, 2024
88d1f17
Use `hasBodyAndHeaders` to fix TS issues in `fetchBaseQuery.test.tsx`
aryaemami59 Sep 3, 2024
0170457
Fix lint issues related to the `no-prototype-builtins` rule
aryaemami59 Sep 3, 2024
137f315
Fix `no-unsafe-optional-chaining` related problems
aryaemami59 Feb 3, 2024
2f78ece
Fix `@typescript-eslint/prefer-as-const` related problems
aryaemami59 Sep 3, 2024
affc5e8
Fix `no-extra-boolean-cast` related problems
aryaemami59 Sep 3, 2024
a596a5a
Fix `no-constant-condition` related problems
aryaemami59 Feb 3, 2024
b79b9e5
Fix `no-empty` related problems
aryaemami59 Feb 3, 2024
24c50e3
Replace all `Function` references with `AnyFunction`
aryaemami59 Feb 3, 2024
61086e8
Move custom matchers into `vitest.setup.ts`
aryaemami59 Feb 8, 2024
9127134
Fix `@typescript-eslint/no-unnecessary-type-constraint` related problems
aryaemami59 Sep 3, 2024
e6778e9
Disable `prefer-rest-params` inside `composeWithDevTools`
aryaemami59 Feb 8, 2024
d9d6b89
Fix `@typescript-eslint/no-var-requires` related problems
aryaemami59 Feb 3, 2024
f232712
Fix issues related to the `@typescript-eslint/prefer-function-type` rule
aryaemami59 Feb 3, 2024
618b4e2
Fix problems related to the `@typescript-eslint/no-empty-function` rule
aryaemami59 Feb 7, 2024
51521c0
Fix problems related to the `sort-imports` rule
aryaemami59 Sep 3, 2024
8704baa
Replace all `{}` types with `AnyNonNullishValue`
aryaemami59 Feb 3, 2024
9500a85
Remove unused ESLint disable directives
aryaemami59 Sep 4, 2024
a143442
Fix `@typescript-eslint/no-unused-expressions` related issues
aryaemami59 Jul 31, 2024
147cb81
Fix problems related to the `@typescript-eslint/array-type` rule
aryaemami59 Sep 4, 2024
48e889d
Fix `noImplicitReturns`-related issues in `src/tests/utils/helpers.tsx`
aryaemami59 Sep 4, 2024
a93bc7d
Fix issues related to `hasBodyAndHeaders` usage
aryaemami59 Sep 4, 2024
2d307b2
Lint files and check formatting during CI
aryaemami59 Sep 4, 2024
c7c2d3c
Fix TS issues related to `AnyNonNullishValue`
aryaemami59 Sep 5, 2024
d2f46c9
Fix TS issues related to `EmptyObject`
aryaemami59 Sep 5, 2024
2854438
Remove unused imports
aryaemami59 Sep 21, 2024
bc933f4
Resolve remaining lint errors
aryaemami59 Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix problems related to the @typescript-eslint/array-type rule
  • Loading branch information
aryaemami59 committed Oct 22, 2025
commit 147cb81ad5bd04c4bfff4dc0241eca2fc7afd969
13 changes: 7 additions & 6 deletions packages/toolkit/src/combineSlices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type SliceLikeReducerPath<A extends AnySliceLike> =
type SliceLikeState<A extends AnySliceLike> =
A extends SliceLike<any, infer State> ? State : never

export type WithSlice<A extends AnySliceLike> = {
[Path in SliceLikeReducerPath<A>]: SliceLikeState<A>
}
export type WithSlice<A extends AnySliceLike> = Record<
SliceLikeReducerPath<A>,
SliceLikeState<A>
>

type ReducerMap = Record<string, Reducer>

Expand Down Expand Up @@ -292,7 +293,7 @@ export interface CombinedSliceReducer<
}
}

type InitialState<Slices extends Array<AnySliceLike | ReducerMap>> =
type InitialState<Slices extends (AnySliceLike | ReducerMap)[]> =
UnionToIntersection<
Slices[number] extends infer Slice
? Slice extends AnySliceLike
Expand All @@ -307,7 +308,7 @@ const isSliceLike = (
'reducerPath' in maybeSliceLike &&
typeof maybeSliceLike.reducerPath === 'string'

const getReducers = (slices: Array<AnySliceLike | ReducerMap>) =>
const getReducers = (slices: (AnySliceLike | ReducerMap)[]) =>
slices.flatMap((sliceOrMap) =>
isSliceLike(sliceOrMap)
? [[sliceOrMap.reducerPath, sliceOrMap.reducer] as const]
Expand Down Expand Up @@ -368,7 +369,7 @@ const original = (state: any) => {
const emptyObject = {}
const noopReducer: Reducer<Record<string, any>> = (state = emptyObject) => state

export function combineSlices<Slices extends Array<AnySliceLike | ReducerMap>>(
export function combineSlices<Slices extends (AnySliceLike | ReducerMap)[]>(
...slices: Slices
): CombinedSliceReducer<Id<InitialState<Slices>>> {
const reducerMap = Object.fromEntries<Reducer>(getReducers(slices))
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export interface ConfigureStoreOptions<
enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E
}

export type Middlewares<S> = ReadonlyArray<Middleware<AnyNonNullishValue, S>>
export type Middlewares<S> = readonly Middleware<AnyNonNullishValue, S>[]

type Enhancers = ReadonlyArray<StoreEnhancer>
type Enhancers = readonly StoreEnhancer[]

/**
* A Redux store returned by `configureStore()`. Supports dispatching
Expand Down
12 changes: 6 additions & 6 deletions packages/toolkit/src/createReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export type ActionMatcherDescription<S, A extends Action> = {
reducer: CaseReducer<S, NoInfer<A>>
}

export type ReadonlyActionMatcherDescriptionCollection<S> = ReadonlyArray<
ActionMatcherDescription<S, any>
>
export type ReadonlyActionMatcherDescriptionCollection<S> =
readonly ActionMatcherDescription<S, any>[]

export type ActionMatcherDescriptionCollection<S> = Array<
ActionMatcherDescription<S, any>
>
export type ActionMatcherDescriptionCollection<S> = ActionMatcherDescription<
S,
any
>[]

/**
* A *case reducer* is a reducer function for a specific action type. Case
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/entities/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ export interface EntityStateAdapter<T, Id extends EntityId> {

updateMany<S extends DraftableEntityState<T, Id>>(
state: PreventAny<S, T, Id>,
updates: ReadonlyArray<Update<T, Id>>,
updates: readonly Update<T, Id>[],
): S
updateMany<S extends DraftableEntityState<T, Id>>(
state: PreventAny<S, T, Id>,
updates: PayloadAction<ReadonlyArray<Update<T, Id>>>,
updates: PayloadAction<readonly Update<T, Id>[]>,
): S

upsertOne<S extends DraftableEntityState<T, Id>>(
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/entities/sorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function createSortedStateAdapter<T, Id extends EntityId>(
}

function updateManyMutably(
updates: ReadonlyArray<Update<T, Id>>,
updates: readonly Update<T, Id>[],
state: R,
): void {
let appliedUpdates = false
Expand Down
6 changes: 3 additions & 3 deletions packages/toolkit/src/entities/unsorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function createUnsortedStateAdapter<T, Id extends EntityId>(
}

function takeNewKey(
keys: Record<string, Id>,
keys: Record<EntityId, Id>,
update: Update<T, Id>,
state: R,
): boolean {
Expand Down Expand Up @@ -132,9 +132,9 @@ export function createUnsortedStateAdapter<T, Id extends EntityId>(
updates: readonly Update<T, Id>[],
state: R,
): void {
const newKeys: Record<string, Id> = {}
const newKeys: Record<EntityId, Id> = {}

const updatesPerEntity: Record<string, Update<T, Id>> = {}
const updatesPerEntity: Record<EntityId, Update<T, Id>> = {}

updates.forEach((update) => {
// Only apply updates to entities that currently exist
Expand Down
16 changes: 6 additions & 10 deletions packages/toolkit/src/query/core/buildSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ import type {
InfiniteQuerySubState,
MutationSubState,
QueryCacheKey,
QueryKeys,
QueryState,
QuerySubState,
RequestStatusFlags,
RootState as _RootState,
} from './apiState'
import { QueryStatus, getRequestStatusFlags } from './apiState'
import { getMutationCacheKey } from './buildSlice'
import type { AllQueryKeys } from './buildThunks'
import { getNextPageParam, getPreviousPageParam } from './buildThunks'
import type { createSelector as _createSelector } from './rtkImports'
import { createNextState } from './rtkImports'
import {
type AllQueryKeys,
getNextPageParam,
getPreviousPageParam,
} from './buildThunks'

export type SkipToken = typeof skipToken
/**
Expand Down Expand Up @@ -338,12 +334,12 @@ export function buildSelectors<

function selectInvalidatedBy(
state: RootState,
tags: ReadonlyArray<TagDescription<string> | null | undefined>,
): Array<{
tags: readonly (TagDescription<string> | null | undefined)[],
): {
endpointName: string
originalArgs: any
queryCacheKey: QueryCacheKey
}> {
}[] {
const apiState = state[reducerPath]
const toInvalidate = new Set<QueryCacheKey>()
for (const tag of tags.filter(isNotNullish).map(expandTagDescription)) {
Expand Down Expand Up @@ -385,7 +381,7 @@ export function buildSelectors<
>(
state: RootState,
queryName: QueryName,
): Array<QueryArgFromAnyQuery<Definitions[QueryName]>> {
): QueryArgFromAnyQuery<Definitions[QueryName]>[] {
return Object.values(selectQueries(state) as QueryState<any>)
.filter(
(
Expand Down
8 changes: 5 additions & 3 deletions packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,11 @@ export enum DefinitionType {
infinitequery = 'infinitequery',
}

type TagDescriptionArray<TagTypes extends string> = ReadonlyArray<
TagDescription<TagTypes> | undefined | null
>
type TagDescriptionArray<TagTypes extends string> = readonly (
| TagDescription<TagTypes>
| undefined
| null
)[]

export type GetResultDescriptionFn<
TagTypes extends string,
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/query/tests/buildSelector.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('type tests', () => {
completed: boolean
}

type Todos = Array<Todo>
type Todos = Todo[]

const exampleApi = createApi({
reducerPath: 'api',
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('type tests', () => {
completed: boolean
}

type Todos = Array<Todo>
type Todos = Todo[]

const exampleApi = createApi({
reducerPath: 'api',
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/tsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function assertCast<T>(v: any): asserts v is T {

export function safeAssign<T extends object>(
target: T,
...args: Array<Partial<NoInfer<T>>>
...args: Partial<NoInfer<T>>[]
): T {
return Object.assign(target, ...args)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/tests/configureStore.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@ describe('type tests', () => {
const concatenated = gDM().concat(otherMiddleware)

expectTypeOf(concatenated).toMatchTypeOf<
ReadonlyArray<
readonly (
| typeof otherMiddleware
| ThunkMiddleware
| Middleware<AnyNonNullishValue>
>
)[]
>()

return concatenated
Expand Down
12 changes: 6 additions & 6 deletions packages/toolkit/src/tests/createEntityAdapter.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ describe('type tests', () => {
>()

expectTypeOf(slice.actions.addMany).toMatchTypeOf<
ActionCreatorWithPayload<ReadonlyArray<Entity> | Record<string, Entity>>
ActionCreatorWithPayload<readonly Entity[] | Record<string, Entity>>
>()

expectTypeOf(slice.actions.setAll).toMatchTypeOf<
ActionCreatorWithPayload<ReadonlyArray<Entity> | Record<string, Entity>>
ActionCreatorWithPayload<readonly Entity[] | Record<string, Entity>>
>()

expectTypeOf(slice.actions.removeOne).toMatchTypeOf<
Expand All @@ -52,15 +52,15 @@ describe('type tests', () => {
>()

expectTypeOf(slice.actions.setAll).not.toMatchTypeOf<
ActionCreatorWithPayload<ReadonlyArray<Id>>
ActionCreatorWithPayload<readonly Id[]>
>()

expectTypeOf(slice.actions.removeOne).toMatchTypeOf<
ActionCreatorWithPayload<Id>
>()

expectTypeOf(slice.actions.removeMany).toMatchTypeOf<
ActionCreatorWithPayload<ReadonlyArray<Id>>
ActionCreatorWithPayload<readonly Id[]>
>()

expectTypeOf(slice.actions.removeMany).not.toMatchTypeOf<
Expand All @@ -84,15 +84,15 @@ describe('type tests', () => {
>()

expectTypeOf(slice.actions.updateMany).toMatchTypeOf<
ActionCreatorWithPayload<ReadonlyArray<Update<Entity, Id>>>
ActionCreatorWithPayload<readonly Update<Entity, Id>[]>
>()

expectTypeOf(slice.actions.upsertOne).toMatchTypeOf<
ActionCreatorWithPayload<Entity>
>()

expectTypeOf(slice.actions.upsertMany).toMatchTypeOf<
ActionCreatorWithPayload<ReadonlyArray<Entity> | Record<string, Entity>>
ActionCreatorWithPayload<readonly Entity[] | Record<string, Entity>>
>()

expectTypeOf(slice.actions.upsertMany).not.toMatchTypeOf<
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/tests/utils/CustomMatchers.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Assertion, AsymmetricMatchersContaining } from 'vitest'
import 'vitest'

interface CustomMatchers<R = unknown> {
toMatchSequence(...matchers: Array<(arg: any) => boolean>): R
toMatchSequence(...matchers: ((arg: any) => boolean)[]): R
}

declare module 'vitest' {
Expand Down
8 changes: 4 additions & 4 deletions packages/toolkit/src/tsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Tuple } from './utils'

export function safeAssign<T extends object>(
target: T,
...args: Array<Partial<NoInfer<T>>>
...args: Partial<NoInfer<T>>[]
) {
Object.assign(target, ...args)
}
Expand Down Expand Up @@ -108,7 +108,7 @@ type ExtractDispatchFromMiddlewareTuple<
export type ExtractDispatchExtensions<M> =
M extends Tuple<infer MiddlewareTuple>
? ExtractDispatchFromMiddlewareTuple<MiddlewareTuple, AnyNonNullishValue>
: M extends ReadonlyArray<Middleware>
: M extends readonly Middleware[]
? ExtractDispatchFromMiddlewareTuple<[...M], AnyNonNullishValue>
: never

Expand All @@ -128,7 +128,7 @@ type ExtractStoreExtensionsFromEnhancerTuple<
export type ExtractStoreExtensions<E> =
E extends Tuple<infer EnhancerTuple>
? ExtractStoreExtensionsFromEnhancerTuple<EnhancerTuple, AnyNonNullishValue>
: E extends ReadonlyArray<StoreEnhancer>
: E extends readonly StoreEnhancer[]
? UnionToIntersection<
E[number] extends StoreEnhancer<infer Ext>
? Ext extends AnyNonNullishValue
Expand All @@ -154,7 +154,7 @@ type ExtractStateExtensionsFromEnhancerTuple<
export type ExtractStateExtensions<E> =
E extends Tuple<infer EnhancerTuple>
? ExtractStateExtensionsFromEnhancerTuple<EnhancerTuple, AnyNonNullishValue>
: E extends ReadonlyArray<StoreEnhancer>
: E extends readonly StoreEnhancer[]
? UnionToIntersection<
E[number] extends StoreEnhancer<any, infer StateExt>
? StateExt extends AnyNonNullishValue
Expand Down
14 changes: 7 additions & 7 deletions packages/toolkit/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

export class Tuple<Items extends ReadonlyArray<unknown> = []> extends Array<
export class Tuple<Items extends readonly unknown[] = []> extends Array<
Items[number]
> {
constructor(length: number)
Expand All @@ -40,26 +40,26 @@ export class Tuple<Items extends ReadonlyArray<unknown> = []> extends Array<
return Tuple as any
}

override concat<AdditionalItems extends ReadonlyArray<unknown>>(
override concat<AdditionalItems extends readonly unknown[]>(
items: Tuple<AdditionalItems>,
): Tuple<[...Items, ...AdditionalItems]>
override concat<AdditionalItems extends ReadonlyArray<unknown>>(
override concat<AdditionalItems extends readonly unknown[]>(
items: AdditionalItems,
): Tuple<[...Items, ...AdditionalItems]>
override concat<AdditionalItems extends ReadonlyArray<unknown>>(
override concat<AdditionalItems extends readonly unknown[]>(
...items: AdditionalItems
): Tuple<[...Items, ...AdditionalItems]>
override concat(...arr: any[]) {
return super.concat.apply(this, arr)
}

prepend<AdditionalItems extends ReadonlyArray<unknown>>(
prepend<AdditionalItems extends readonly unknown[]>(
items: Tuple<AdditionalItems>,
): Tuple<[...AdditionalItems, ...Items]>
prepend<AdditionalItems extends ReadonlyArray<unknown>>(
prepend<AdditionalItems extends readonly unknown[]>(
items: AdditionalItems,
): Tuple<[...AdditionalItems, ...Items]>
prepend<AdditionalItems extends ReadonlyArray<unknown>>(
prepend<AdditionalItems extends readonly unknown[]>(
...items: AdditionalItems
): Tuple<[...AdditionalItems, ...Items]>
prepend(...arr: any[]) {
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ afterAll(() => {
declare global {
namespace jest {
interface Matchers<R> {
toMatchSequence(...matchers: Array<(arg: any) => boolean>): R
toMatchSequence(...matchers: ((arg: any) => boolean)[]): R
}
}
}

expect.extend({
toMatchSequence(
_actions: UnknownAction[],
...matchers: Array<(arg: any) => boolean>
...matchers: ((arg: any) => boolean)[]
) {
const actions = _actions.concat()
actions.shift() // remove INIT
Expand Down