Skip to content

Instantly share code, notes, and snippets.

@oliverbenns
Last active September 25, 2018 12:31
Show Gist options
  • Save oliverbenns/106e2cb11343aa183791dc9753567787 to your computer and use it in GitHub Desktop.
Save oliverbenns/106e2cb11343aa183791dc9753567787 to your computer and use it in GitHub Desktop.
Reducer issue
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