Skip to content

Commit b79c497

Browse files
committed
Convert all interfaces to type aliases
- We do this because per #4467, `type` aliases are less prone to `TS4023` errors.
1 parent f01bc8e commit b79c497

File tree

73 files changed

+274
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+274
-274
lines changed

packages/toolkit/src/actionCreatorInvariantMiddleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Middleware } from 'redux'
22
import { isActionCreator as isRTKAction } from './createAction'
33
import type { AnyFunction } from './tsHelpers'
44

5-
export interface ActionCreatorInvariantMiddlewareOptions {
5+
export type ActionCreatorInvariantMiddlewareOptions = {
66
/**
77
* The function to identify whether a value is an action creator.
88
* The default checks for a function with a static type property and match method.

packages/toolkit/src/combineSlices.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
} from './tsHelpers'
1111
import { emplace } from './utils'
1212

13-
interface SliceLike<ReducerPath extends string, State> {
13+
type SliceLike<ReducerPath extends string, State> = {
1414
reducerPath: ReducerPath
1515
reducer: Reducer<State>
1616
}
@@ -36,7 +36,7 @@ type ExistingSliceLike<DeclaredState> = {
3636
>
3737
}[keyof DeclaredState]
3838

39-
export interface InjectConfig {
39+
export type InjectConfig = {
4040
/**
4141
* Allow replacing reducer with a different reference. Normally, an error will be thrown if a different reducer instance to the one already injected is used.
4242
*/
@@ -46,10 +46,10 @@ export interface InjectConfig {
4646
/**
4747
* A reducer that allows for slices/reducers to be injected after initialisation.
4848
*/
49-
export interface CombinedSliceReducer<
49+
export type CombinedSliceReducer<
5050
InitialState,
5151
DeclaredState = InitialState,
52-
> extends Reducer<DeclaredState, UnknownAction, Partial<DeclaredState>> {
52+
> = Reducer<DeclaredState, UnknownAction, Partial<DeclaredState>> & {
5353
/**
5454
* Provide a type for slices that will be injected lazily.
5555
*

packages/toolkit/src/configureStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ const IS_PRODUCTION = process.env.NODE_ENV === 'production'
3939
*
4040
* @public
4141
*/
42-
export interface ConfigureStoreOptions<
42+
export type ConfigureStoreOptions<
4343
S = any,
4444
A extends Action = UnknownAction,
4545
M extends Tuple<Middlewares<S>> = Tuple<Middlewares<S>>,
4646
E extends Tuple<Enhancers> = Tuple<Enhancers>,
4747
P = S,
48-
> {
48+
> = {
4949
/**
5050
* A single reducer function that will be used as the root reducer, or an
5151
* object of slice reducers that will be passed to `combineReducers()`.

packages/toolkit/src/createAction.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,19 @@ export type BaseActionCreator<P, T extends string, M = never, E = never> = {
102102
*
103103
* @public
104104
*/
105-
export interface ActionCreatorWithPreparedPayload<
105+
export type ActionCreatorWithPreparedPayload<
106106
Args extends unknown[],
107107
P,
108108
T extends string = string,
109109
E = never,
110110
M = never,
111-
> extends BaseActionCreator<P, T, M, E> {
111+
> = BaseActionCreator<P, T, M, E> &
112112
/**
113113
* Calling this {@link redux#ActionCreator} with `Args` will return
114114
* an Action with a payload of type `P` and (depending on the `PrepareAction`
115115
* method used) a `meta`- and `error` property of types `M` and `E` respectively.
116116
*/
117-
(...args: Args): PayloadAction<P, T, M, E>
118-
}
117+
((...args: Args) => PayloadAction<P, T, M, E>)
119118

120119
/**
121120
* An action creator of type `T` that takes an optional payload of type `P`.
@@ -124,15 +123,16 @@ export interface ActionCreatorWithPreparedPayload<
124123
*
125124
* @public
126125
*/
127-
export interface ActionCreatorWithOptionalPayload<P, T extends string = string>
128-
extends BaseActionCreator<P, T> {
126+
export type ActionCreatorWithOptionalPayload<
127+
P,
128+
T extends string = string,
129+
> = BaseActionCreator<P, T> &
129130
/**
130131
* Calling this {@link redux#ActionCreator} with an argument will
131132
* return a {@link PayloadAction} of type `T` with a payload of `P`.
132133
* Calling it without an argument will return a PayloadAction with a payload of `undefined`.
133134
*/
134-
(payload?: P): PayloadAction<P, T>
135-
}
135+
((payload?: P) => PayloadAction<P, T>)
136136

137137
/**
138138
* An action creator of type `T` that takes no payload.
@@ -141,14 +141,13 @@ export interface ActionCreatorWithOptionalPayload<P, T extends string = string>
141141
*
142142
* @public
143143
*/
144-
export interface ActionCreatorWithoutPayload<T extends string = string>
145-
extends BaseActionCreator<undefined, T> {
146-
/**
147-
* Calling this {@link redux#ActionCreator} will
148-
* return a {@link PayloadAction} of type `T` with a payload of `undefined`
149-
*/
150-
(noArgument: void): PayloadAction<undefined, T>
151-
}
144+
export type ActionCreatorWithoutPayload<T extends string = string> =
145+
BaseActionCreator<undefined, T> &
146+
/**
147+
* Calling this {@link redux#ActionCreator} will
148+
* return a {@link PayloadAction} of type `T` with a payload of `undefined`
149+
*/
150+
((noArgument: void) => PayloadAction<undefined, T>)
152151

153152
/**
154153
* An action creator of type `T` that requires a payload of type P.
@@ -157,14 +156,15 @@ export interface ActionCreatorWithoutPayload<T extends string = string>
157156
*
158157
* @public
159158
*/
160-
export interface ActionCreatorWithPayload<P, T extends string = string>
161-
extends BaseActionCreator<P, T> {
159+
export type ActionCreatorWithPayload<
160+
P,
161+
T extends string = string,
162+
> = BaseActionCreator<P, T> &
162163
/**
163164
* Calling this {@link redux#ActionCreator} with an argument will
164165
* return a {@link PayloadAction} of type `T` with a payload of `P`
165166
*/
166-
(payload: P): PayloadAction<P, T>
167-
}
167+
((payload: P) => PayloadAction<P, T>)
168168

169169
/**
170170
* An action creator of type `T` whose `payload` type could not be inferred. Accepts everything as `payload`.
@@ -173,16 +173,14 @@ export interface ActionCreatorWithPayload<P, T extends string = string>
173173
*
174174
* @public
175175
*/
176-
export interface ActionCreatorWithNonInferrablePayload<
177-
T extends string = string,
178-
> extends BaseActionCreator<unknown, T> {
179-
/**
180-
* Calling this {@link redux#ActionCreator} with an argument will
181-
* return a {@link PayloadAction} of type `T` with a payload
182-
* of exactly the type of the argument.
183-
*/
184-
<PT>(payload: PT): PayloadAction<PT, T>
185-
}
176+
export type ActionCreatorWithNonInferrablePayload<T extends string = string> =
177+
BaseActionCreator<unknown, T> &
178+
/**
179+
* Calling this {@link redux#ActionCreator} with an argument will
180+
* return a {@link PayloadAction} of type `T` with a payload
181+
* of exactly the type of the argument.
182+
*/
183+
(<PT>(payload: PT) => PayloadAction<PT, T>)
186184

187185
/**
188186
* An action creator that produces actions with a `payload` attribute.

packages/toolkit/src/createAsyncThunk.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import type {
1616
SafePromise,
1717
} from './tsHelpers'
1818

19-
export interface BaseThunkAPI<
19+
export type BaseThunkAPI<
2020
S,
2121
E,
2222
D extends Dispatch = Dispatch,
2323
RejectedValue = unknown,
2424
RejectedMeta = unknown,
2525
FulfilledMeta = unknown,
26-
> {
26+
> = {
2727
dispatch: D
2828
getState: () => S
2929
extra: E
@@ -51,7 +51,7 @@ export interface BaseThunkAPI<
5151
/**
5252
* @public
5353
*/
54-
export interface SerializedError {
54+
export type SerializedError = {
5555
name?: string
5656
message?: string
5757
stack?: string
@@ -110,7 +110,7 @@ export const miniSerializeError = (value: any): SerializedError => {
110110
return { message: String(value) }
111111
}
112112

113-
export interface AsyncThunkConfig {
113+
export type AsyncThunkConfig = {
114114
state?: unknown
115115
dispatch?: ThunkDispatch<unknown, unknown, UnknownAction>
116116
extra?: unknown
@@ -441,7 +441,7 @@ export type OverrideThunkApiConfigs<OldConfig, NewConfig> = Id<
441441
NewConfig & Omit<OldConfig, keyof NewConfig>
442442
>
443443

444-
interface CreateAsyncThunk<CurriedThunkApiConfig extends AsyncThunkConfig> {
444+
type CreateAsyncThunk<CurriedThunkApiConfig extends AsyncThunkConfig> = {
445445
/**
446446
*
447447
* @param typePrefix
@@ -710,7 +710,7 @@ export const createAsyncThunk = /* @__PURE__ */ (() => {
710710
return createAsyncThunk as CreateAsyncThunk<AsyncThunkConfig>
711711
})()
712712

713-
interface UnwrappableAction {
713+
type UnwrappableAction = {
714714
payload: any
715715
meta?: any
716716
error?: any

packages/toolkit/src/createReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { freezeDraftable } from './utils'
1616
*/
1717
export type Actions<T extends keyof any = string> = Record<T, Action>
1818

19-
export interface ActionMatcherDescription<S, A extends Action> {
19+
export type ActionMatcherDescription<S, A extends Action> = {
2020
matcher: TypeGuard<A>
2121
reducer: CaseReducer<S, NoInfer<A>>
2222
}

packages/toolkit/src/createSlice.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type InjectIntoConfig<NewReducerPath extends string> = InjectConfig & {
5353
*
5454
* @public
5555
*/
56+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
5657
export interface Slice<
5758
State = any,
5859
CaseReducers extends SliceCaseReducers<State> = SliceCaseReducers<State>,
@@ -189,13 +190,13 @@ type InjectedSlice<
189190
*
190191
* @public
191192
*/
192-
export interface CreateSliceOptions<
193+
export type CreateSliceOptions<
193194
State = any,
194195
CR extends SliceCaseReducers<State> = SliceCaseReducers<State>,
195196
Name extends string = string,
196197
ReducerPath extends string = Name,
197198
Selectors extends SliceSelectors<State> = SliceSelectors<State>,
198-
> {
199+
> = {
199200
/**
200201
* The slice's name. Used to namespace the generated action types.
201202
*/
@@ -290,16 +291,16 @@ export type CaseReducerDefinition<
290291
*
291292
* @public
292293
*/
293-
export interface CaseReducerWithPrepare<State, Action extends PayloadAction> {
294+
export type CaseReducerWithPrepare<State, Action extends PayloadAction> = {
294295
reducer: CaseReducer<State, Action>
295296
prepare: PrepareAction<Action['payload']>
296297
}
297298

298-
export interface CaseReducerWithPrepareDefinition<
299+
export type CaseReducerWithPrepareDefinition<
299300
State,
300301
Action extends PayloadAction,
301-
> extends CaseReducerWithPrepare<State, Action>,
302-
ReducerDefinition<ReducerType.reducerWithPrepare> {}
302+
> = CaseReducerWithPrepare<State, Action> &
303+
ReducerDefinition<ReducerType.reducerWithPrepare>
303304

304305
type AsyncThunkSliceReducerConfig<
305306
State,
@@ -347,11 +348,11 @@ type PreventCircular<ThunkApiConfig> = {
347348
: ThunkApiConfig[K]
348349
}
349350

350-
interface AsyncThunkCreator<
351+
type AsyncThunkCreator<
351352
State,
352353
CurriedThunkApiConfig extends
353354
PreventCircular<AsyncThunkConfig> = PreventCircular<AsyncThunkConfig>,
354-
> {
355+
> = {
355356
<Returned, ThunkArg = void>(
356357
payloadCreator: AsyncThunkPayloadCreator<
357358
Returned,
@@ -395,7 +396,7 @@ interface AsyncThunkCreator<
395396
>
396397
}
397398

398-
export interface ReducerCreators<State> {
399+
export type ReducerCreators<State> = {
399400
reducer(
400401
caseReducer: CaseReducer<State, PayloadAction>,
401402
): CaseReducerDefinition<State, PayloadAction>
@@ -578,7 +579,7 @@ function getType(slice: string, actionKey: string): string {
578579
return `${slice}/${actionKey}`
579580
}
580581

581-
interface BuildCreateSliceConfig {
582+
type BuildCreateSliceConfig = {
582583
creators?: {
583584
asyncThunk?: typeof asyncThunkCreator
584585
}
@@ -860,7 +861,7 @@ function wrapSelector<State, NewState, S extends Selector<State>>(
860861
*/
861862
export const createSlice = /* @__PURE__ */ buildCreateSlice()
862863

863-
interface ReducerHandlingContext<State> {
864+
type ReducerHandlingContext<State> = {
864865
sliceCaseReducersByName: Record<
865866
string,
866867
| CaseReducer<State, any>
@@ -874,7 +875,7 @@ interface ReducerHandlingContext<State> {
874875
actionCreators: Record<string, AnyFunction>
875876
}
876877

877-
interface ReducerHandlingContextMethods<State> {
878+
type ReducerHandlingContextMethods<State> = {
878879
/**
879880
* Adds a case reducer to handle a single action type.
880881
* @param actionCreator - Either a plain action type string, or an action creator generated by [`createAction`](./createAction) that can be used to determine the action type.
@@ -946,7 +947,7 @@ interface ReducerHandlingContextMethods<State> {
946947
): ReducerHandlingContextMethods<State>
947948
}
948949

949-
interface ReducerDetails {
950+
type ReducerDetails = {
950951
/** The key the reducer was defined under */
951952
reducerName: string
952953
/** The predefined action type, i.e. `${slice.name}/${reducerName}` */

packages/toolkit/src/devtoolsExtension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { AnyFunction, EmptyObject } from './tsHelpers'
55
/**
66
* @public
77
*/
8-
export interface DevToolsEnhancerOptions {
8+
export type DevToolsEnhancerOptions = {
99
/**
1010
* the instance name to be showed on the monitor page. Default value is `document.title`.
1111
* If not specified and there's no document title, it will consist of `tabId` and `instanceId`.
@@ -209,7 +209,7 @@ export interface DevToolsEnhancerOptions {
209209

210210
type Compose = typeof compose
211211

212-
interface ComposeWithDevTools {
212+
type ComposeWithDevTools = {
213213
(options: DevToolsEnhancerOptions): Compose
214214
<StoreExt extends EmptyObject>(
215215
...funcs: Array<StoreEnhancer<StoreExt>>

packages/toolkit/src/dynamicMiddleware/react/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export type UseDispatchWithMiddlewareHook<
2121
DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>,
2222
> = () => TSHelpersExtractDispatchExtensions<Middlewares> & DispatchType
2323

24-
export interface CreateDispatchWithMiddlewareHook<
24+
export type CreateDispatchWithMiddlewareHook<
2525
State = any,
2626
DispatchType extends Dispatch<UnknownAction> = Dispatch<UnknownAction>,
27-
> {
27+
> = {
2828
<
2929
Middlewares extends [
3030
Middleware<any, State, DispatchType>,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createDynamicMiddleware } from '../index'
66

77
const untypedInstance = createDynamicMiddleware()
88

9+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
910
interface AppDispatch extends ThunkDispatch<number, undefined, UnknownAction> {
1011
(n: 1): 1
1112
}

0 commit comments

Comments
 (0)