I upgraded to typescript 4-beta and my reducers where my state is typed with Record<string, string> are showing my that when I create new property with value in them, then the value can be undefined. I dont know if I really understand what is going on or is this some sort of bug. On version 3.9 it this kind of error did not show up.
Type '{ [x: string]: string | undefined; }' is not assignable to type 'Record<string, string>'. Index signatures are incompatible. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'.
Here is TS playground with example.
type State = Record<string, string>
const initialState = {};
const reducer = (state: State = initialState, action: {type: string; payload: {key: string, value: string}}):State => {
switch(action.type) {
case "foo":
return {
...state,
[action.payload.key]: action.payload.value
}
default:
return state;
}
}
Many thanks maybe I am just dumb and I am doing somthing wrong.