Skip to content

Commit fcf015b

Browse files
committed
Revert createReducer() type change
Things are fixed in v1.10.5.
1 parent 57a9231 commit fcf015b

File tree

5 files changed

+15
-27
lines changed

5 files changed

+15
-27
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"index.d.ts"
4848
],
4949
"dependencies": {
50-
"immer": "^1.10.3",
50+
"immer": "^1.10.5",
5151
"redux": "^4.0.0",
5252
"redux-devtools-extension": "^2.13.7",
5353
"redux-immutable-state-invariant": "^2.1.0",

src/createReducer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import createNextState, { Draft, Immutable } from 'immer'
1+
import createNextState, { Draft } from 'immer'
22
import { AnyAction, Action, Reducer } from 'redux'
33

44
/**
@@ -44,10 +44,10 @@ export interface CaseReducersMapObject<S = any, A extends Action = AnyAction> {
4444
* case redeucers.
4545
*/
4646
export function createReducer<S = any, A extends Action = AnyAction>(
47-
initialState: Immutable<S>,
47+
initialState: S,
4848
actionsMap: CaseReducersMapObject<S, A>
49-
): Reducer<Immutable<S>, A> {
50-
return function(state = initialState, action): Immutable<S> {
49+
): Reducer<S, A> {
50+
return function(state = initialState, action): S {
5151
// @ts-ignore createNextState() produces an Immutable<Draft<S>> rather
5252
// than an Immutable<S>, and TypeScript cannot find out how to reconcile
5353
// these two types.

src/createSlice.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Immutable } from 'immer'
21
import { Action, AnyAction, ActionCreator, Reducer } from 'redux'
32
import { createAction, PayloadAction } from './createAction'
43
import { createReducer, CaseReducersMapObject } from './createReducer'
@@ -51,7 +50,7 @@ export interface CreateSliceOptions<
5150
/**
5251
* The initial state to be returned by the slice reducer.
5352
*/
54-
initialState: Immutable<S>
53+
initialState: S
5554

5655
/**
5756
* A mapping from action types to action-type-specific *case reducer*
@@ -79,7 +78,7 @@ export function createSlice<
7978
CR extends CaseReducersMapObject<S, A> = CaseReducersMapObject<S, A>
8079
>(
8180
options: CreateSliceOptions<S, A, CR>
82-
): Slice<Immutable<S>, A, Extract<keyof CR, string>> {
81+
): Slice<S, A, Extract<keyof CR, string>> {
8382
const { slice = '', initialState } = options
8483
const reducers = options.reducers || {}
8584
const actionKeys = Object.keys(reducers)

type-tests/files/createReducer.typetest.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,14 @@ import { AnyAction, createReducer, Reducer } from 'redux-starter-kit'
5858
}
5959

6060
/*
61-
* Test: createReducer() reducers are typed to return readonly states.
61+
* Test: createReducer() ensures state type is mutable within a case reducer.
6262
*/
6363
{
64-
const initialCounters = {
65-
a: 0,
66-
b: 0
67-
}
64+
const initialState: { readonly counter: number } = { counter: 0 }
6865

69-
const reducer = createReducer(initialCounters, {
70-
incrementA: state => {
71-
state.a += 1
72-
},
73-
incrementB: state => {
74-
state.b += 1
66+
createReducer(initialState, {
67+
increment: state => {
68+
state.counter += 1
7569
}
7670
})
77-
78-
const newCounters = reducer(initialCounters, { type: 'incrementA' })
79-
80-
// typings:expect-error
81-
newCounters.a++
8271
}

0 commit comments

Comments
 (0)