Last active
September 25, 2018 12:31
-
-
Save oliverbenns/106e2cb11343aa183791dc9753567787 to your computer and use it in GitHub Desktop.
Reducer issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AnyAction, Reducer } from 'redux' | |
type UserState = Readonly<{ | |
id: number | |
}> | |
export const initialState: UserState = { | |
id: -1 | |
} | |
const userReducer: Reducer<UserState> = (state = initialState, action: any) => { | |
return { | |
id: 0, | |
foo: 'bar' // Why doesn't this raise an error? | |
} | |
} | |
const userReducer2: Reducer<UserState> = (state = initialState, action: any): UserState => { | |
return { | |
id: 0, | |
foo: 'bar' //this raises an issue due to explicitly defining the return type. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment