Skip to content

Commit 6549f8b

Browse files
committed
Fix TS issues related to AnyNonNullishValue
1 parent 91ac9e4 commit 6549f8b

13 files changed

+46
-49
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>,
@@ -293,7 +294,7 @@ type AsyncThunkActionCreator<
293294
*/
294295
export type AsyncThunkOptions<
295296
ThunkArg = void,
296-
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
297+
ThunkApiConfig extends AsyncThunkConfig = EmptyObject,
297298
> = {
298299
/**
299300
* 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/baseQueryTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ThunkDispatch } from '@reduxjs/toolkit'
2-
import type { AnyNonNullishValue } from '../tsHelpers'
2+
import type { AnyObject } from '../tsHelpers'
33
import type { MaybePromise, UnwrapPromise } from './tsHelpers'
44

55
export interface BaseQueryApi {
@@ -37,8 +37,8 @@ export type BaseQueryFn<
3737
Args = any,
3838
Result = unknown,
3939
Error = unknown,
40-
DefinitionExtraOptions = AnyNonNullishValue,
41-
Meta = AnyNonNullishValue,
40+
DefinitionExtraOptions = AnyObject,
41+
Meta = AnyObject,
4242
> = (
4343
args: Args,
4444
api: BaseQueryApi,

packages/toolkit/src/query/core/buildMiddleware/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
ThunkDispatch,
77
UnknownAction,
88
} from '@reduxjs/toolkit'
9-
import type { AnyNonNullishValue } from '../../../tsHelpers'
9+
import type { AnyNonNullishValue, EmptyObject } from '../../../tsHelpers'
1010
import type { Api, ApiContext } from '../../apiTypes'
1111
import type {
1212
AssertTagTypes,
@@ -66,7 +66,7 @@ export interface BuildSubMiddlewareInput
6666
>,
6767
queryCacheKey: string,
6868
override?: Partial<QueryThunkArg>,
69-
): AsyncThunkAction<ThunkResult, QueryThunkArg, AnyNonNullishValue>
69+
): AsyncThunkAction<ThunkResult, QueryThunkArg, EmptyObject>
7070
isThisApiSliceAction: (action: Action) => boolean
7171
}
7272

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 { BaseQueryArg, BaseQueryFn } from './baseQueryTypes'
66
import type { CombinedState } from './core/apiState'
@@ -324,7 +324,9 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
324324
endpoints,
325325
)) {
326326
if (typeof partialDefinition === 'function') {
327-
partialDefinition(context.endpointDefinitions[endpointName])
327+
;(partialDefinition as AnyFunction)(
328+
context.endpointDefinitions[endpointName],
329+
)
328330
} else {
329331
Object.assign(
330332
context.endpointDefinitions[endpointName] || {},
@@ -335,13 +337,7 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
335337
}
336338
return api
337339
},
338-
} as Api<
339-
BaseQueryFn,
340-
AnyNonNullishValue,
341-
string,
342-
string,
343-
Modules[number]['name']
344-
>
340+
} as Api<BaseQueryFn, AnyObject, string, string, Modules[number]['name']>
345341

346342
const initializedModules = modules.map((m) =>
347343
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/combineSlices.test-d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Reducer, Slice, WithSlice } from '@reduxjs/toolkit'
22
import { combineSlices } from '@reduxjs/toolkit'
33
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query'
4-
import type { AnyNonNullishValue } from '../tsHelpers'
4+
import type { EmptyObject } from '../tsHelpers'
55

6-
declare const stringSlice: Slice<string, AnyNonNullishValue, 'string'>
6+
declare const stringSlice: Slice<string, EmptyObject, 'string'>
77

8-
declare const numberSlice: Slice<number, AnyNonNullishValue, 'number'>
8+
declare const numberSlice: Slice<number, EmptyObject, 'number'>
99

1010
declare const booleanReducer: Reducer<boolean>
1111

@@ -39,7 +39,7 @@ describe('type tests', () => {
3939

4040
expectTypeOf(
4141
rootReducer(undefined, { type: '' }),
42-
).toEqualTypeOf<AnyNonNullishValue>()
42+
).toMatchTypeOf<EmptyObject>()
4343

4444
const declaredLazy =
4545
combineSlices().withLazyLoadedSlices<WithSlice<typeof numberSlice>>()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { noop } from '@internal/tests/utils/helpers'
2-
import type { AnyNonNullishValue } from '@internal/tsHelpers'
2+
import type { AnyNonNullishValue, EmptyObject } from '@internal/tsHelpers'
33
import type {
44
Action,
55
ConfigureStoreOptions,
@@ -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', () => {
@@ -213,7 +213,7 @@ describe('type tests', () => {
213213
expectTypeOf(store3.anotherProperty).toBeNumber()
214214

215215
const someStateExtendingEnhancer: StoreEnhancer<
216-
AnyNonNullishValue,
216+
EmptyObject,
217217
{ someProperty: string }
218218
> =
219219
(next) =>
@@ -230,7 +230,7 @@ describe('type tests', () => {
230230
}
231231

232232
const anotherStateExtendingEnhancer: StoreEnhancer<
233-
AnyNonNullishValue,
233+
EmptyObject,
234234
{ anotherProperty: number }
235235
> =
236236
(next) =>

0 commit comments

Comments
 (0)