Skip to content

Commit 75e99d7

Browse files
author
ben.durrant
committed
Switch advised syntax for create.reducer
1 parent 898ed5a commit 75e99d7

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

docs/api/createSlice.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ const todosSlice = createSlice({
161161
todos: [],
162162
} as TodoState,
163163
reducers: (create) => ({
164-
deleteTodo: create.reducer((state, action: PayloadAction<number>) => {
164+
deleteTodo: create.reducer<number>((state, action) => {
165165
state.todos.splice(action.payload, 1)
166166
}),
167167
addTodo: create.preparedReducer(
@@ -209,7 +209,7 @@ A standard slice case reducer.
209209
- **reducer** The slice case reducer to use.
210210

211211
```ts no-transpile
212-
create.reducer((state, action: PayloadAction<Todo>) => {
212+
create.reducer<Todo>((state, action) => {
213213
state.todos.push(action.payload)
214214
})
215215
```

packages/toolkit/src/tests/createSlice.typetest.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -599,18 +599,14 @@ const value = actionCreators.anyKey
599599
}>()
600600

601601
return {
602-
normalReducer: create.reducer(
603-
(state, action: PayloadAction<string>) => {
604-
expectType<TestState>(state)
605-
expectType<string>(action.payload)
606-
}
607-
),
608-
optionalReducer: create.reducer(
609-
(state, action: PayloadAction<string | undefined>) => {
610-
expectType<TestState>(state)
611-
expectType<string | undefined>(action.payload)
612-
}
613-
),
602+
normalReducer: create.reducer<string>((state, action) => {
603+
expectType<TestState>(state)
604+
expectType<string>(action.payload)
605+
}),
606+
optionalReducer: create.reducer<string | undefined>((state, action) => {
607+
expectType<TestState>(state)
608+
expectType<string | undefined>(action.payload)
609+
}),
614610
noActionReducer: create.reducer((state) => {
615611
expectType<TestState>(state)
616612
}),
@@ -788,7 +784,7 @@ const value = actionCreators.anyKey
788784
start: create.reducer((state) => {
789785
state.status = 'loading'
790786
}),
791-
success: create.reducer((state, action: PayloadAction<T>) => {
787+
success: create.reducer<T>((state, action) => {
792788
state.data = castDraft(action.payload)
793789
state.status = 'finished'
794790
}),

0 commit comments

Comments
 (0)