Skip to content

Commit 8f6add0

Browse files
committed
Re-switch Slice generics order
1 parent a34bf93 commit 8f6add0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/createSlice.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import { createReducer, CaseReducers, CaseReducer } from './createReducer'
1717
export type SliceActionCreator<P> = PayloadActionCreator<P>
1818

1919
export interface Slice<
20-
CaseReducers extends SliceCaseReducerDefinitions<State, PayloadActions>,
21-
State = any
20+
State = any,
21+
CaseReducers extends SliceCaseReducerDefinitions<State, PayloadActions> = {
22+
[key: string]: any
23+
}
2224
> {
2325
/**
2426
* The slice name.
@@ -185,15 +187,15 @@ export function createSlice<
185187
>(
186188
options: CreateSliceOptions<State, CaseReducers> &
187189
RestrictCaseReducerDefinitionsToMatchReducerAndPrepare<State, CaseReducers>
188-
): Slice<CaseReducers, State>
190+
): Slice<State, CaseReducers>
189191

190192
// internal definition is a little less restrictive
191193
export function createSlice<
192194
State,
193195
CaseReducers extends SliceCaseReducerDefinitions<State, any>
194196
>(
195197
options: CreateSliceOptions<State, CaseReducers>
196-
): Slice<CaseReducers, State> {
198+
): Slice<State, CaseReducers> {
197199
const { name, initialState } = options
198200
if (!name) {
199201
throw new Error('`name` is a required option for createSlice')

type-tests/files/createSlice.typetest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ function expectType<T>(t: T) {
174174
counter.caseReducers.increment
175175
)
176176

177+
// Should match positively for reducers with prepare callback
178+
expectType<(state: number, action: PayloadAction<number>) => number | void>(
179+
counter.caseReducers.decrement
180+
)
181+
177182
// Should not mismatch the payload if it's a simple reducer
178183
// typings:expect-error
179184
expectType<(state: number, action: PayloadAction<string>) => number | void>(

0 commit comments

Comments
 (0)