In the following example im trying to figure out why my typing works for all parts of my object apart from my reducer return type?
If i explicitly set: reducer: (state, action): CounterState
the compiler complains (as expected) that i'm not returning the right state. The thing is, i don't see why i should have to do this seeing as i'm already enforcing this within my Config
type??
The simplified example:
interface CounterState {
counter: number;
}
type Reducer = () => CounterState
const reducer1: Reducer = () => ({
counter: 1,
foo: 'bar' // no errors, why?
})
const reducer2: Reducer = (): CounterState => ({
counter: 1,
foo: 'bar' // error: Object literal may only specify known properties
})