Skip to content

Commit a42c045

Browse files
committed
Fix TS issues related to AnyNonNullishValue
1 parent 243040d commit a42c045

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
@@ -28,6 +28,7 @@ import { executeReducerBuilderCallback } from './mapBuilders'
2828
import type {
2929
AnyFunction,
3030
AnyNonNullishValue,
31+
EmptyObject,
3132
Id,
3233
TypeGuard,
3334
} from './tsHelpers'
@@ -304,7 +305,7 @@ type AsyncThunkSliceReducerConfig<
304305
State,
305306
ThunkArg,
306307
Returned = unknown,
307-
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
308+
ThunkApiConfig extends AsyncThunkConfig = EmptyObject,
308309
> = {
309310
pending?: CaseReducer<
310311
State,
@@ -331,7 +332,7 @@ type AsyncThunkSliceReducerDefinition<
331332
State,
332333
ThunkArg,
333334
Returned = unknown,
334-
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
335+
ThunkApiConfig extends AsyncThunkConfig = EmptyObject,
335336
> = AsyncThunkSliceReducerConfig<State, ThunkArg, Returned, ThunkApiConfig> &
336337
ReducerDefinition<ReducerType.asyncThunk> & {
337338
payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>
@@ -372,8 +373,7 @@ interface AsyncThunkCreator<
372373
<
373374
Returned,
374375
ThunkArg,
375-
ThunkApiConfig extends
376-
PreventCircular<AsyncThunkConfig> = AnyNonNullishValue,
376+
ThunkApiConfig extends PreventCircular<AsyncThunkConfig> = EmptyObject,
377377
>(
378378
payloadCreator: AsyncThunkPayloadCreator<
379379
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'
@@ -414,7 +414,9 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
414414
endpoints,
415415
)) {
416416
if (typeof partialDefinition === 'function') {
417-
partialDefinition(context.endpointDefinitions[endpointName])
417+
;(partialDefinition as AnyFunction)(
418+
context.endpointDefinitions[endpointName],
419+
)
418420
} else {
419421
Object.assign(
420422
context.endpointDefinitions[endpointName] || {},
@@ -425,13 +427,7 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
425427
}
426428
return api
427429
},
428-
} as Api<
429-
BaseQueryFn,
430-
AnyNonNullishValue,
431-
string,
432-
string,
433-
Modules[number]['name']
434-
>
430+
} as Api<BaseQueryFn, AnyObject, string, string, Modules[number]['name']>
435431

436432
const initializedModules = modules.map((m) =>
437433
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)