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
Replace all {} types with AnyNonNullishValue
  • Loading branch information
aryaemami59 committed Oct 22, 2025
commit 8704baa0a367059596f86499ee4e465da59112f1
2 changes: 1 addition & 1 deletion packages/toolkit/src/combineSlices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface CombinedSliceReducer<
* const withCustom = rootReducer.inject({ reducerPath: "customName", reducer: customSlice.reducer })
* ```
*/
withLazyLoadedSlices<Lazy = {}>(): CombinedSliceReducer<
withLazyLoadedSlices<Lazy>(): CombinedSliceReducer<
InitialState,
Id<DeclaredState & Partial<Lazy>>
>
Expand Down
8 changes: 4 additions & 4 deletions packages/toolkit/src/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ import {
} from 'redux'
import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension'
import { composeWithDevTools } from './devtoolsExtension'

import type { GetDefaultEnhancers } from './getDefaultEnhancers'
import { buildGetDefaultEnhancers } from './getDefaultEnhancers'
import type {
GetDefaultMiddleware,
ThunkMiddlewareFor,
} from './getDefaultMiddleware'
import { buildGetDefaultMiddleware } from './getDefaultMiddleware'
import type {
AnyNonNullishValue,
ExtractDispatchExtensions,
ExtractStateExtensions,
ExtractStoreExtensions,
UnknownIfNonSpecific,
} from './tsHelpers'
import type { Tuple } from './utils'
import type { GetDefaultEnhancers } from './getDefaultEnhancers'
import { buildGetDefaultEnhancers } from './getDefaultEnhancers'

/**
* Options for `configureStore()`.
Expand Down Expand Up @@ -93,7 +93,7 @@ export interface ConfigureStoreOptions<
enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E
}

export type Middlewares<S> = ReadonlyArray<Middleware<{}, S>>
export type Middlewares<S> = ReadonlyArray<Middleware<AnyNonNullishValue, S>>

type Enhancers = ReadonlyArray<StoreEnhancer>

Expand Down
5 changes: 3 additions & 2 deletions packages/toolkit/src/createAction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isAction } from 'redux'
import type {
AnyFunction,
AnyNonNullishValue,
IfMaybeUndefined,
IfVoid,
IsAny,
Expand Down Expand Up @@ -28,12 +29,12 @@ export type PayloadAction<
payload: P
type: T
} & ([M] extends [never]
? {}
? AnyNonNullishValue
: {
meta: M
}) &
([E] extends [never]
? {}
? AnyNonNullishValue
: {
error: E
})
Expand Down
19 changes: 13 additions & 6 deletions packages/toolkit/src/createAsyncThunk.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import type { Dispatch, UnknownAction } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import type { ActionCreatorWithPreparedPayload } from './createAction'
import type {
ActionCreatorWithPreparedPayload,
PayloadAction,
} from './createAction'
import { createAction } from './createAction'
import { isAnyOf } from './matchers'
import { nanoid } from './nanoid'
import type {
AnyNonNullishValue,
FallbackIfUnknown,
Id,
IsAny,
IsUnknown,
SafePromise,
} from './tsHelpers'

// @ts-ignore we need the import of these types due to a bundling issue.
type _Keep = PayloadAction | ActionCreatorWithPreparedPayload<any, unknown>

export type BaseThunkAPI<
S,
E,
Expand Down Expand Up @@ -213,7 +220,7 @@ export type AsyncThunkPayloadCreatorReturnValue<
export type AsyncThunkPayloadCreator<
Returned,
ThunkArg = void,
ThunkApiConfig extends AsyncThunkConfig = {},
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
> = (
arg: ThunkArg,
thunkAPI: GetThunkAPI<ThunkApiConfig>,
Expand Down Expand Up @@ -309,7 +316,7 @@ type AsyncThunkActionCreator<
*/
export type AsyncThunkOptions<
ThunkArg = void,
ThunkApiConfig extends AsyncThunkConfig = {},
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
> = {
/**
* A method to control whether the asyncThunk should be executed. Has access to the
Expand Down Expand Up @@ -371,7 +378,7 @@ export type AsyncThunkOptions<

export type AsyncThunkPendingActionCreator<
ThunkArg,
ThunkApiConfig = {},
ThunkApiConfig = AnyNonNullishValue,
> = ActionCreatorWithPreparedPayload<
[string, ThunkArg, GetPendingMeta<ThunkApiConfig>?],
undefined,
Expand All @@ -386,7 +393,7 @@ export type AsyncThunkPendingActionCreator<

export type AsyncThunkRejectedActionCreator<
ThunkArg,
ThunkApiConfig = {},
ThunkApiConfig = AnyNonNullishValue,
> = ActionCreatorWithPreparedPayload<
[
Error | null,
Expand Down Expand Up @@ -415,7 +422,7 @@ export type AsyncThunkRejectedActionCreator<
export type AsyncThunkFulfilledActionCreator<
Returned,
ThunkArg,
ThunkApiConfig = {},
ThunkApiConfig = AnyNonNullishValue,
> = ActionCreatorWithPreparedPayload<
[Returned, string, ThunkArg, GetFulfilledMeta<ThunkApiConfig>?],
Returned,
Expand Down
16 changes: 11 additions & 5 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ import type {
TypedActionCreator,
} from './mapBuilders'
import { executeReducerBuilderCallback } from './mapBuilders'
import type { AnyFunction, Id, TypeGuard } from './tsHelpers'
import type {
AnyFunction,
AnyNonNullishValue,
Id,
TypeGuard,
} from './tsHelpers'
import { getOrInsertComputed } from './utils'

const asyncThunkSymbol = /* @__PURE__ */ Symbol.for(
Expand Down Expand Up @@ -303,7 +308,7 @@ type AsyncThunkSliceReducerConfig<
State,
ThunkArg,
Returned = unknown,
ThunkApiConfig extends AsyncThunkConfig = {},
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
> = AsyncThunkReducers<State, ThunkArg, Returned, ThunkApiConfig> & {
options?: AsyncThunkOptions<ThunkArg, ThunkApiConfig>
}
Expand All @@ -312,7 +317,7 @@ type AsyncThunkSliceReducerDefinition<
State,
ThunkArg,
Returned = unknown,
ThunkApiConfig extends AsyncThunkConfig = {},
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
> = AsyncThunkSliceReducerConfig<State, ThunkArg, Returned, ThunkApiConfig> &
ReducerDefinition<ReducerType.asyncThunk> & {
payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>
Expand Down Expand Up @@ -353,7 +358,8 @@ interface AsyncThunkCreator<
<
Returned,
ThunkArg,
ThunkApiConfig extends PreventCircular<AsyncThunkConfig> = {},
ThunkApiConfig extends
PreventCircular<AsyncThunkConfig> = AnyNonNullishValue,
>(
payloadCreator: AsyncThunkPayloadCreator<
Returned,
Expand Down Expand Up @@ -550,7 +556,7 @@ export type ValidateSliceCaseReducers<
? {
prepare(...a: never[]): Omit<A, 'type'>
}
: {}
: AnyNonNullishValue
}

function getType(slice: string, actionKey: string): string {
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/devtoolsExtension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Action, ActionCreator, StoreEnhancer } from 'redux'
import { compose } from 'redux'
import type { AnyFunction } from './tsHelpers'
import type { AnyFunction, AnyNonNullishValue } from './tsHelpers'

/**
* @public
Expand Down Expand Up @@ -209,7 +209,7 @@ type Compose = typeof compose

interface ComposeWithDevTools {
(options: DevToolsEnhancerOptions): Compose
<StoreExt extends {}>(
<StoreExt extends AnyNonNullishValue>(
...funcs: StoreEnhancer<StoreExt>[]
): StoreEnhancer<StoreExt>
}
Expand Down
8 changes: 7 additions & 1 deletion packages/toolkit/src/dynamicMiddleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { compose } from 'redux'
import { createAction } from '../createAction'
import { isAllOf } from '../matchers'
import { nanoid } from '../nanoid'
import type { AnyNonNullishValue } from '../tsHelpers'
import { getOrInsertComputed } from '../utils'
import type {
AddMiddleware,
Expand All @@ -11,6 +12,7 @@ import type {
MiddlewareEntry,
WithMiddleware,
} from './types'

export type {
DynamicMiddlewareInstance,
GetDispatchType as GetDispatch,
Expand Down Expand Up @@ -66,7 +68,11 @@ export const createDynamicMiddleware = <
{ withTypes: () => addMiddleware },
) as AddMiddleware<State, DispatchType>

const getFinalMiddleware: Middleware<{}, State, DispatchType> = (api) => {
const getFinalMiddleware: Middleware<
AnyNonNullishValue,
State,
DispatchType
> = (api) => {
const appliedMiddleware = Array.from(middlewareMap.values()).map((entry) =>
getOrInsertComputed(entry.applied, api, entry.middleware),
)
Expand Down
13 changes: 11 additions & 2 deletions packages/toolkit/src/dynamicMiddleware/tests/index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Action, Middleware, UnknownAction } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import { configureStore } from '../../configureStore'
import type { AnyNonNullishValue } from '../../tsHelpers'
import { createDynamicMiddleware } from '../index'

const untypedInstance = createDynamicMiddleware()
Expand All @@ -19,8 +20,16 @@ const store = configureStore({
gDM().prepend(typedInstance.middleware).concat(staticMiddleware),
})

declare const compatibleMiddleware: Middleware<{}, number, AppDispatch>
declare const incompatibleMiddleware: Middleware<{}, string, AppDispatch>
declare const compatibleMiddleware: Middleware<
AnyNonNullishValue,
number,
AppDispatch
>
declare const incompatibleMiddleware: Middleware<
AnyNonNullishValue,
string,
AppDispatch
>

declare const addedMiddleware: Middleware<(n: 2) => 2>

Expand Down
13 changes: 11 additions & 2 deletions packages/toolkit/src/dynamicMiddleware/tests/react.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Context } from 'react'
import type { ReactReduxContextValue } from 'react-redux'
import type { Action, Middleware, UnknownAction } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import type { AnyNonNullishValue } from '../../tsHelpers'
import { createDynamicMiddleware } from '../react'

interface AppDispatch extends ThunkDispatch<number, undefined, UnknownAction> {
Expand All @@ -12,8 +13,16 @@ const untypedInstance = createDynamicMiddleware()

const typedInstance = createDynamicMiddleware<number, AppDispatch>()

declare const compatibleMiddleware: Middleware<{}, number, AppDispatch>
declare const incompatibleMiddleware: Middleware<{}, string, AppDispatch>
declare const compatibleMiddleware: Middleware<
AnyNonNullishValue,
number,
AppDispatch
>
declare const incompatibleMiddleware: Middleware<
AnyNonNullishValue,
string,
AppDispatch
>

declare const customContext: Context<ReactReduxContextValue | null>

Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/getDefaultMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { createImmutableStateInvariantMiddleware } from './immutableStateInvaria

import type { SerializableStateInvariantMiddlewareOptions } from './serializableStateInvariantMiddleware'
import { createSerializableStateInvariantMiddleware } from './serializableStateInvariantMiddleware'
import type { ExcludeFromTuple } from './tsHelpers'
import type { AnyNonNullishValue, ExcludeFromTuple } from './tsHelpers'
import { Tuple } from './utils'

function isBoolean(x: any): x is boolean {
Expand All @@ -30,7 +30,7 @@ interface GetDefaultMiddlewareOptions {

export type ThunkMiddlewareFor<
S,
O extends GetDefaultMiddlewareOptions = {},
O extends GetDefaultMiddlewareOptions = AnyNonNullishValue,
> = O extends {
thunk: false
}
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/mapBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
CaseReducer,
CaseReducers,
} from './createReducer'
import type { TypeGuard } from './tsHelpers'
import type { AnyNonNullishValue, TypeGuard } from './tsHelpers'
import type { AsyncThunk, AsyncThunkConfig } from './createAsyncThunk'

export type AsyncThunkReducers<
Expand Down Expand Up @@ -188,7 +188,7 @@ const reducer = createReducer(initialState, builder => {
})
```
*/
addDefaultCase(reducer: CaseReducer<State, Action>): {}
addDefaultCase(reducer: CaseReducer<State, Action>): AnyNonNullishValue
}

export function executeReducerBuilderCallback<S>(
Expand Down
5 changes: 3 additions & 2 deletions packages/toolkit/src/query/baseQueryTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ThunkDispatch } from '@reduxjs/toolkit'
import type { AnyObject } from '../tsHelpers'
import type { MaybePromise, UnwrapPromise } from './tsHelpers'

export interface BaseQueryApi {
Expand Down Expand Up @@ -40,8 +41,8 @@ export type BaseQueryFn<
Args = any,
Result = unknown,
Error = unknown,
DefinitionExtraOptions = {},
Meta = {},
DefinitionExtraOptions = AnyObject,
Meta = AnyObject,
> = (
args: Args,
api: BaseQueryApi,
Expand Down
8 changes: 4 additions & 4 deletions packages/toolkit/src/query/core/buildMiddleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import type {
ThunkDispatch,
UnknownAction,
} from '@reduxjs/toolkit'
import type { AnyNonNullishValue } from '../../../tsHelpers'
import type {
EndpointDefinitions,
FullTagDescription,
} from '../../endpointDefinitions'
import type { QueryStatus, QuerySubState, RootState } from '../apiState'
import type { QueryThunkArg } from '../buildThunks'
import type { ApiEndpointQuery } from '../module'
import { createAction, isAction } from '../rtkImports'
import { buildBatchedActionsHandler } from './batchActions'
import { buildCacheCollectionHandler } from './cacheCollection'
Expand All @@ -24,7 +25,6 @@ import type {
InternalMiddlewareState,
} from './types'
import { buildWindowEventHandler } from './windowEventHandling'
import type { ApiEndpointQuery } from '../module'
export type { ReferenceCacheCollection } from './cacheCollection'
export type {
MutationCacheLifecycleApi,
Expand All @@ -50,7 +50,7 @@ export function buildMiddleware<

const actions = {
invalidateTags: createAction<
Array<TagTypes | FullTagDescription<TagTypes> | null | undefined>
(TagTypes | FullTagDescription<TagTypes> | null | undefined)[]
>(`${reducerPath}/invalidateTags`),
}

Expand All @@ -67,7 +67,7 @@ export function buildMiddleware<
]

const middleware: Middleware<
{},
AnyNonNullishValue,
RootState<Definitions, string, ReducerPath>,
ThunkDispatch<any, any, UnknownAction>
> = (mwApi) => {
Expand Down
Loading