Skip to content

Commit 33416f8

Browse files
committed
Replace all {} types with AnyNonNullishValue
1 parent c952a3f commit 33416f8

28 files changed

+169
-125
lines changed

packages/toolkit/src/combineSlices.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Reducer, StateFromReducersMapObject, UnknownAction } from 'redux'
22
import { combineReducers } from 'redux'
33
import { nanoid } from './nanoid'
44
import type {
5+
AnyNonNullishValue,
56
Id,
67
NonUndefined,
78
Tail,
@@ -79,7 +80,7 @@ export interface CombinedSliceReducer<
7980
* const withCustom = rootReducer.inject({ reducerPath: "customName", reducer: customSlice.reducer })
8081
* ```
8182
*/
82-
withLazyLoadedSlices<Lazy = {}>(): CombinedSliceReducer<
83+
withLazyLoadedSlices<Lazy = AnyNonNullishValue>(): CombinedSliceReducer<
8384
InitialState,
8485
Id<DeclaredState & Partial<Lazy>>
8586
>
@@ -121,7 +122,7 @@ export interface CombinedSliceReducer<
121122
config?: InjectConfig,
122123
): CombinedSliceReducer<
123124
InitialState,
124-
Id<DeclaredState & WithSlice<SliceLike<ReducerPath, State>>>
125+
Id<DeclaredState & WithSlice<SliceLike<ReducerPath, string>>>
125126
>
126127

127128
/**

packages/toolkit/src/configureStore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ import {
1616
} from 'redux'
1717
import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension'
1818
import { composeWithDevTools } from './devtoolsExtension'
19-
19+
import type { GetDefaultEnhancers } from './getDefaultEnhancers'
20+
import { buildGetDefaultEnhancers } from './getDefaultEnhancers'
2021
import type {
2122
GetDefaultMiddleware,
2223
ThunkMiddlewareFor,
2324
} from './getDefaultMiddleware'
2425
import { buildGetDefaultMiddleware } from './getDefaultMiddleware'
2526
import type {
27+
AnyNonNullishValue,
2628
ExtractDispatchExtensions,
2729
ExtractStateExtensions,
2830
ExtractStoreExtensions,
2931
UnknownIfNonSpecific,
3032
} from './tsHelpers'
3133
import type { Tuple } from './utils'
32-
import type { GetDefaultEnhancers } from './getDefaultEnhancers'
33-
import { buildGetDefaultEnhancers } from './getDefaultEnhancers'
3434

3535
/**
3636
* Options for `configureStore()`.
@@ -88,7 +88,7 @@ export interface ConfigureStoreOptions<
8888
enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E
8989
}
9090

91-
export type Middlewares<S> = ReadonlyArray<Middleware<{}, S>>
91+
export type Middlewares<S> = ReadonlyArray<Middleware<AnyNonNullishValue, S>>
9292

9393
type Enhancers = ReadonlyArray<StoreEnhancer>
9494

packages/toolkit/src/createAction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isAction } from 'redux'
22
import type {
3-
AnyFunction,
3+
AnyNonNullishValue,
44
IfMaybeUndefined,
55
IfVoid,
66
IsAny,
@@ -28,12 +28,12 @@ export type PayloadAction<
2828
payload: P
2929
type: T
3030
} & ([M] extends [never]
31-
? {}
31+
? AnyNonNullishValue
3232
: {
3333
meta: M
3434
}) &
3535
([E] extends [never]
36-
? {}
36+
? AnyNonNullishValue
3737
: {
3838
error: E
3939
})

packages/toolkit/src/createAsyncThunk.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import type { Dispatch, UnknownAction } from 'redux'
22
import type { ThunkDispatch } from 'redux-thunk'
3-
import type { ActionCreatorWithPreparedPayload } from './createAction'
3+
import type {
4+
ActionCreatorWithPreparedPayload,
5+
PayloadAction,
6+
} from './createAction'
47
import { createAction } from './createAction'
58
import { isAnyOf } from './matchers'
69
import { nanoid } from './nanoid'
710
import type {
11+
AnyNonNullishValue,
812
FallbackIfUnknown,
913
Id,
1014
IsAny,
1115
IsUnknown,
1216
SafePromise,
1317
} from './tsHelpers'
1418

19+
// @ts-ignore we need the import of these types due to a bundling issue.
20+
type _Keep = PayloadAction | ActionCreatorWithPreparedPayload<any, unknown>
21+
1522
export type BaseThunkAPI<
1623
S,
1724
E,
@@ -213,7 +220,7 @@ export type AsyncThunkPayloadCreatorReturnValue<
213220
export type AsyncThunkPayloadCreator<
214221
Returned,
215222
ThunkArg = void,
216-
ThunkApiConfig extends AsyncThunkConfig = {},
223+
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
217224
> = (
218225
arg: ThunkArg,
219226
thunkAPI: GetThunkAPI<ThunkApiConfig>,
@@ -286,7 +293,7 @@ type AsyncThunkActionCreator<
286293
*/
287294
export type AsyncThunkOptions<
288295
ThunkArg = void,
289-
ThunkApiConfig extends AsyncThunkConfig = {},
296+
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
290297
> = {
291298
/**
292299
* A method to control whether the asyncThunk should be executed. Has access to the
@@ -348,7 +355,7 @@ export type AsyncThunkOptions<
348355

349356
export type AsyncThunkPendingActionCreator<
350357
ThunkArg,
351-
ThunkApiConfig = {},
358+
ThunkApiConfig = AnyNonNullishValue,
352359
> = ActionCreatorWithPreparedPayload<
353360
[string, ThunkArg, GetPendingMeta<ThunkApiConfig>?],
354361
undefined,
@@ -363,7 +370,7 @@ export type AsyncThunkPendingActionCreator<
363370

364371
export type AsyncThunkRejectedActionCreator<
365372
ThunkArg,
366-
ThunkApiConfig = {},
373+
ThunkApiConfig = AnyNonNullishValue,
367374
> = ActionCreatorWithPreparedPayload<
368375
[
369376
Error | null,
@@ -392,7 +399,7 @@ export type AsyncThunkRejectedActionCreator<
392399
export type AsyncThunkFulfilledActionCreator<
393400
Returned,
394401
ThunkArg,
395-
ThunkApiConfig = {},
402+
ThunkApiConfig = AnyNonNullishValue,
396403
> = ActionCreatorWithPreparedPayload<
397404
[Returned, string, ThunkArg, GetFulfilledMeta<ThunkApiConfig>?],
398405
Returned,

packages/toolkit/src/createSlice.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ type AsyncThunkSliceReducerConfig<
304304
State,
305305
ThunkArg,
306306
Returned = unknown,
307-
ThunkApiConfig extends AsyncThunkConfig = {},
307+
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
308308
> = {
309309
pending?: CaseReducer<
310310
State,
@@ -331,7 +331,7 @@ type AsyncThunkSliceReducerDefinition<
331331
State,
332332
ThunkArg,
333333
Returned = unknown,
334-
ThunkApiConfig extends AsyncThunkConfig = {},
334+
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
335335
> = AsyncThunkSliceReducerConfig<State, ThunkArg, Returned, ThunkApiConfig> &
336336
ReducerDefinition<ReducerType.asyncThunk> & {
337337
payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>
@@ -372,7 +372,8 @@ interface AsyncThunkCreator<
372372
<
373373
Returned,
374374
ThunkArg,
375-
ThunkApiConfig extends PreventCircular<AsyncThunkConfig> = {},
375+
ThunkApiConfig extends
376+
PreventCircular<AsyncThunkConfig> = AnyNonNullishValue,
376377
>(
377378
payloadCreator: AsyncThunkPayloadCreator<
378379
Returned,
@@ -569,7 +570,7 @@ export type ValidateSliceCaseReducers<
569570
? {
570571
prepare(...a: never[]): Omit<A, 'type'>
571572
}
572-
: {}
573+
: AnyNonNullishValue
573574
}
574575

575576
function getType(slice: string, actionKey: string): string {

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 { AnyNonNullishValue } 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 {}>(
212+
<StoreExt extends AnyNonNullishValue>(
213213
...funcs: StoreEnhancer<StoreExt>[]
214214
): StoreEnhancer<StoreExt>
215215
}

packages/toolkit/src/dynamicMiddleware/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { compose } from 'redux'
33
import { createAction } from '../createAction'
44
import { isAllOf } from '../matchers'
55
import { nanoid } from '../nanoid'
6+
import type { AnyNonNullishValue } from '../tsHelpers'
67
import { emplace, find } from '../utils'
78
import type {
89
AddMiddleware,
@@ -11,11 +12,6 @@ import type {
1112
MiddlewareEntry,
1213
WithMiddleware,
1314
} from './types'
14-
export type {
15-
DynamicMiddlewareInstance,
16-
GetDispatchType as GetDispatch,
17-
MiddlewareApiConfig,
18-
} from './types'
1915

2016
const createMiddlewareEntry = <
2117
State = any,
@@ -71,7 +67,9 @@ export const createDynamicMiddleware = <
7167
{ withTypes: () => addMiddleware },
7268
) as AddMiddleware<State, DispatchType>
7369

74-
const getFinalMiddleware: Middleware<{}, State, DispatchType> = (api) => {
70+
const getFinalMiddleware: Middleware<AnyNonNullishValue, State, Dispatch> = (
71+
api,
72+
) => {
7573
const appliedMiddleware = Array.from(middlewareMap.values()).map((entry) =>
7674
emplace(entry.applied, api, { insert: () => entry.middleware(api) }),
7775
)

packages/toolkit/src/dynamicMiddleware/tests/index.test-d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Action, Middleware, UnknownAction } from 'redux'
22
import type { ThunkDispatch } from 'redux-thunk'
33
import { configureStore } from '../../configureStore'
4+
import type { AnyNonNullishValue } from '../../tsHelpers'
45
import { createDynamicMiddleware } from '../index'
56

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

22-
declare const compatibleMiddleware: Middleware<{}, number, AppDispatch>
23-
declare const incompatibleMiddleware: Middleware<{}, string, AppDispatch>
23+
declare const compatibleMiddleware: Middleware<
24+
AnyNonNullishValue,
25+
number,
26+
AppDispatch
27+
>
28+
declare const incompatibleMiddleware: Middleware<
29+
AnyNonNullishValue,
30+
string,
31+
AppDispatch
32+
>
2433

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

packages/toolkit/src/dynamicMiddleware/tests/react.test-d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Context } from 'react'
22
import type { ReactReduxContextValue } from 'react-redux'
33
import type { Action, Middleware, UnknownAction } from 'redux'
44
import type { ThunkDispatch } from 'redux-thunk'
5+
import type { AnyNonNullishValue } from '../../tsHelpers'
56
import { createDynamicMiddleware } from '../react'
67

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

1314
const typedInstance = createDynamicMiddleware<number, AppDispatch>()
1415

15-
declare const compatibleMiddleware: Middleware<{}, number, AppDispatch>
16-
declare const incompatibleMiddleware: Middleware<{}, string, AppDispatch>
16+
declare const compatibleMiddleware: Middleware<
17+
AnyNonNullishValue,
18+
number,
19+
AppDispatch
20+
>
21+
declare const incompatibleMiddleware: Middleware<
22+
AnyNonNullishValue,
23+
string,
24+
AppDispatch
25+
>
1726

1827
declare const customContext: Context<ReactReduxContextValue | null>
1928

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 { ExcludeFromTuple } from './tsHelpers'
13+
import type { AnyNonNullishValue, 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 = {},
33+
O extends GetDefaultMiddlewareOptions = AnyNonNullishValue,
3434
> = O extends {
3535
thunk: false
3636
}

0 commit comments

Comments
 (0)