Skip to content

Commit 64c16b8

Browse files
committed
Replace all {} types with AnyNonNullishValue
1 parent 086fa8b commit 64c16b8

28 files changed

+172
-107
lines changed

packages/toolkit/src/combineSlices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export interface CombinedSliceReducer<
7979
* const withCustom = rootReducer.inject({ reducerPath: "customName", reducer: customSlice.reducer })
8080
* ```
8181
*/
82-
withLazyLoadedSlices<Lazy = {}>(): CombinedSliceReducer<
82+
withLazyLoadedSlices<Lazy>(): CombinedSliceReducer<
8383
InitialState,
8484
Id<DeclaredState & Partial<Lazy>>
8585
>

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()`.
@@ -93,7 +93,7 @@ export interface ConfigureStoreOptions<
9393
enhancers?: (getDefaultEnhancers: GetDefaultEnhancers<M>) => E
9494
}
9595

96-
export type Middlewares<S> = ReadonlyArray<Middleware<{}, S>>
96+
export type Middlewares<S> = ReadonlyArray<Middleware<AnyNonNullishValue, S>>
9797

9898
type Enhancers = ReadonlyArray<StoreEnhancer>
9999

packages/toolkit/src/createAction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { isAction } from 'redux'
22
import type {
33
AnyFunction,
4+
AnyNonNullishValue,
45
IfMaybeUndefined,
56
IfVoid,
67
IsAny,
@@ -28,12 +29,12 @@ export type PayloadAction<
2829
payload: P
2930
type: T
3031
} & ([M] extends [never]
31-
? {}
32+
? AnyNonNullishValue
3233
: {
3334
meta: M
3435
}) &
3536
([E] extends [never]
36-
? {}
37+
? AnyNonNullishValue
3738
: {
3839
error: E
3940
})

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>,
@@ -309,7 +316,7 @@ type AsyncThunkActionCreator<
309316
*/
310317
export type AsyncThunkOptions<
311318
ThunkArg = void,
312-
ThunkApiConfig extends AsyncThunkConfig = {},
319+
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
313320
> = {
314321
/**
315322
* A method to control whether the asyncThunk should be executed. Has access to the
@@ -371,7 +378,7 @@ export type AsyncThunkOptions<
371378

372379
export type AsyncThunkPendingActionCreator<
373380
ThunkArg,
374-
ThunkApiConfig = {},
381+
ThunkApiConfig = AnyNonNullishValue,
375382
> = ActionCreatorWithPreparedPayload<
376383
[string, ThunkArg, GetPendingMeta<ThunkApiConfig>?],
377384
undefined,
@@ -386,7 +393,7 @@ export type AsyncThunkPendingActionCreator<
386393

387394
export type AsyncThunkRejectedActionCreator<
388395
ThunkArg,
389-
ThunkApiConfig = {},
396+
ThunkApiConfig = AnyNonNullishValue,
390397
> = ActionCreatorWithPreparedPayload<
391398
[
392399
Error | null,
@@ -415,7 +422,7 @@ export type AsyncThunkRejectedActionCreator<
415422
export type AsyncThunkFulfilledActionCreator<
416423
Returned,
417424
ThunkArg,
418-
ThunkApiConfig = {},
425+
ThunkApiConfig = AnyNonNullishValue,
419426
> = ActionCreatorWithPreparedPayload<
420427
[Returned, string, ThunkArg, GetFulfilledMeta<ThunkApiConfig>?],
421428
Returned,

packages/toolkit/src/createSlice.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ import type {
2525
import { createReducer } from './createReducer'
2626
import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders'
2727
import { executeReducerBuilderCallback } from './mapBuilders'
28-
import type { AnyFunction, Id, TypeGuard } from './tsHelpers'
28+
import type {
29+
AnyFunction,
30+
AnyNonNullishValue,
31+
Id,
32+
TypeGuard,
33+
} from './tsHelpers'
2934
import { getOrInsertComputed } from './utils'
3035

3136
const asyncThunkSymbol = /* @__PURE__ */ Symbol.for(
@@ -299,7 +304,7 @@ type AsyncThunkSliceReducerConfig<
299304
State,
300305
ThunkArg,
301306
Returned = unknown,
302-
ThunkApiConfig extends AsyncThunkConfig = {},
307+
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
303308
> = {
304309
pending?: CaseReducer<
305310
State,
@@ -326,7 +331,7 @@ type AsyncThunkSliceReducerDefinition<
326331
State,
327332
ThunkArg,
328333
Returned = unknown,
329-
ThunkApiConfig extends AsyncThunkConfig = {},
334+
ThunkApiConfig extends AsyncThunkConfig = AnyNonNullishValue,
330335
> = AsyncThunkSliceReducerConfig<State, ThunkArg, Returned, ThunkApiConfig> &
331336
ReducerDefinition<ReducerType.asyncThunk> & {
332337
payloadCreator: AsyncThunkPayloadCreator<Returned, ThunkArg, ThunkApiConfig>
@@ -367,7 +372,8 @@ interface AsyncThunkCreator<
367372
<
368373
Returned,
369374
ThunkArg,
370-
ThunkApiConfig extends PreventCircular<AsyncThunkConfig> = {},
375+
ThunkApiConfig extends
376+
PreventCircular<AsyncThunkConfig> = AnyNonNullishValue,
371377
>(
372378
payloadCreator: AsyncThunkPayloadCreator<
373379
Returned,
@@ -564,7 +570,7 @@ export type ValidateSliceCaseReducers<
564570
? {
565571
prepare(...a: never[]): Omit<A, 'type'>
566572
}
567-
: {}
573+
: AnyNonNullishValue
568574
}
569575

570576
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 } from './tsHelpers'
3+
import type { AnyFunction, 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: 7 additions & 1 deletion
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 { getOrInsertComputed } from '../utils'
78
import type {
89
AddMiddleware,
@@ -11,6 +12,7 @@ import type {
1112
MiddlewareEntry,
1213
WithMiddleware,
1314
} from './types'
15+
1416
export type {
1517
DynamicMiddlewareInstance,
1618
GetDispatchType as GetDispatch,
@@ -66,7 +68,11 @@ export const createDynamicMiddleware = <
6668
{ withTypes: () => addMiddleware },
6769
) as AddMiddleware<State, DispatchType>
6870

69-
const getFinalMiddleware: Middleware<{}, State, DispatchType> = (api) => {
71+
const getFinalMiddleware: Middleware<
72+
AnyNonNullishValue,
73+
State,
74+
DispatchType
75+
> = (api) => {
7076
const appliedMiddleware = Array.from(middlewareMap.values()).map((entry) =>
7177
getOrInsertComputed(entry.applied, api, entry.middleware),
7278
)

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)