Skip to content

Commit c7c2d3c

Browse files
committed
Fix TS issues related to AnyNonNullishValue
1 parent 2d307b2 commit c7c2d3c

File tree

7 files changed

+19
-22
lines changed

7 files changed

+19
-22
lines changed

packages/toolkit/src/createAsyncThunk.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { isAnyOf } from './matchers'
99
import { nanoid } from './nanoid'
1010
import type {
1111
AnyNonNullishValue,
12+
EmptyObject,
1213
FallbackIfUnknown,
1314
Id,
1415
IsAny,
@@ -220,7 +221,7 @@ export type AsyncThunkPayloadCreatorReturnValue<
220221
export type AsyncThunkPayloadCreator<
221222
Returned,
222223
ThunkArg = void,
223-
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
224+
ThunkApiConfig extends AsyncThunkConfig = EmptyObject,
224225
> = (
225226
arg: ThunkArg,
226227
thunkAPI: GetThunkAPI<ThunkApiConfig>,
@@ -316,7 +317,7 @@ type AsyncThunkActionCreator<
316317
*/
317318
export type AsyncThunkOptions<
318319
ThunkArg = void,
319-
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
320+
ThunkApiConfig extends AsyncThunkConfig = EmptyObject,
320321
> = {
321322
/**
322323
* A method to control whether the asyncThunk should be executed. Has access to the

packages/toolkit/src/createSlice.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { executeReducerBuilderCallback } from './mapBuilders'
3232
import type {
3333
AnyFunction,
3434
AnyNonNullishValue,
35+
EmptyObject,
3536
Id,
3637
TypeGuard,
3738
} from './tsHelpers'
@@ -308,7 +309,7 @@ type AsyncThunkSliceReducerConfig<
308309
State,
309310
ThunkArg,
310311
Returned = unknown,
311-
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
312+
ThunkApiConfig extends AsyncThunkConfig = EmptyObject,
312313
> = AsyncThunkReducers<State, ThunkArg, Returned, ThunkApiConfig> & {
313314
options?: AsyncThunkOptions<ThunkArg, ThunkApiConfig>
314315
}
@@ -317,7 +318,7 @@ type AsyncThunkSliceReducerDefinition<
317318
State,
318319
ThunkArg,
319320
Returned = unknown,
320-
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
321+
ThunkApiConfig extends AsyncThunkConfig = EmptyObject,
321322
> = AsyncThunkSliceReducerConfig<State, ThunkArg, Returned, ThunkApiConfig> &
322323
ReducerDefinition<ReducerType.asyncThunk> & {
323324
payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>
@@ -358,8 +359,7 @@ interface AsyncThunkCreator<
358359
<
359360
Returned,
360361
ThunkArg,
361-
ThunkApiConfig extends
362-
PreventCircular<AsyncThunkConfig> = AnyNonNullishValue,
362+
ThunkApiConfig extends PreventCircular<AsyncThunkConfig> = EmptyObject,
363363
>(
364364
payloadCreator: AsyncThunkPayloadCreator<
365365
Returned,

packages/toolkit/src/devtoolsExtension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Action, ActionCreator, StoreEnhancer } from 'redux'
22
import { compose } from 'redux'
3-
import type { AnyFunction, AnyNonNullishValue } from './tsHelpers'
3+
import type { AnyFunction, EmptyObject } from './tsHelpers'
44

55
/**
66
* @public
@@ -209,7 +209,7 @@ type Compose = typeof compose
209209

210210
interface ComposeWithDevTools {
211211
(options: DevToolsEnhancerOptions): Compose
212-
<StoreExt extends AnyNonNullishValue>(
212+
<StoreExt extends EmptyObject>(
213213
...funcs: StoreEnhancer<StoreExt>[]
214214
): StoreEnhancer<StoreExt>
215215
}

packages/toolkit/src/getDefaultMiddleware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { createImmutableStateInvariantMiddleware } from './immutableStateInvaria
1010

1111
import type { SerializableStateInvariantMiddlewareOptions } from './serializableStateInvariantMiddleware'
1212
import { createSerializableStateInvariantMiddleware } from './serializableStateInvariantMiddleware'
13-
import type { AnyNonNullishValue, ExcludeFromTuple } from './tsHelpers'
13+
import type { EmptyObject, ExcludeFromTuple } from './tsHelpers'
1414
import { Tuple } from './utils'
1515

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

3131
export type ThunkMiddlewareFor<
3232
S,
33-
O extends GetDefaultMiddlewareOptions = AnyNonNullishValue,
33+
O extends GetDefaultMiddlewareOptions = EmptyObject,
3434
> = O extends {
3535
thunk: false
3636
}

packages/toolkit/src/query/createApi.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { UnknownAction } from '@reduxjs/toolkit'
22
import { weakMapMemoize } from 'reselect'
3-
import type { AnyNonNullishValue } from '../tsHelpers'
3+
import type { AnyFunction, AnyObject } from '../tsHelpers'
44
import type { Api, ApiContext, Module, ModuleName } from './apiTypes'
55
import type { BaseQueryFn } from './baseQueryTypes'
66
import type { CombinedState } from './core/apiState'
@@ -417,7 +417,9 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
417417
endpoints,
418418
)) {
419419
if (typeof partialDefinition === 'function') {
420-
partialDefinition(context.endpointDefinitions[endpointName])
420+
;(partialDefinition as AnyFunction)(
421+
context.endpointDefinitions[endpointName],
422+
)
421423
} else {
422424
Object.assign(
423425
context.endpointDefinitions[endpointName] || {},
@@ -428,13 +430,7 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
428430
}
429431
return api
430432
},
431-
} as Api<
432-
BaseQueryFn,
433-
AnyNonNullishValue,
434-
string,
435-
string,
436-
Modules[number]['name']
437-
>
433+
} as Api<BaseQueryFn, AnyObject, string, string, Modules[number]['name']>
438434

439435
const initializedModules = modules.map((m) =>
440436
m.init(api as any, optionsWithDefaults as any, context),

packages/toolkit/src/query/react/ApiProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Context } from 'react'
55
import React, { useContext, useEffect } from 'react'
66
import type { ReactReduxContextValue } from 'react-redux'
77
import { Provider, ReactReduxContext } from 'react-redux'
8-
import type { AnyNonNullishValue } from '../../tsHelpers'
8+
import type { EmptyObject } from '../../tsHelpers'
99

1010
/**
1111
* Can be used as a `Provider` if you **do not already have a Redux store**.
@@ -33,7 +33,7 @@ import type { AnyNonNullishValue } from '../../tsHelpers'
3333
*/
3434
export function ApiProvider(props: {
3535
children: any
36-
api: Api<any, AnyNonNullishValue, any, any>
36+
api: Api<any, EmptyObject, any, any>
3737
setupListeners?: Parameters<typeof setupListeners>[1] | false
3838
context?: Context<ReactReduxContextValue | null>
3939
}) {

packages/toolkit/src/tests/configureStore.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('type tests', () => {
135135
reducer: (): string | null => null,
136136
})
137137

138-
expectTypeOf(store.getState()).toEqualTypeOf<string | null>()
138+
expectTypeOf(store.getState()).toMatchTypeOf<string | null>()
139139
})
140140

141141
test('configureStore() accepts store Tuple for enhancers, but not plain array', () => {

0 commit comments

Comments
 (0)