When working with union typed values in an object array, how should the setState()
function be implemented?
enum SomeStateEnum {
IsRunning,
Name,
}
type PersonState = {
[SomeStateEnum.IsRunning]: boolean;
[SomeStateEnum.Name]: string;
};
const state: PersonState = {
[SomeStateEnum.IsRunning]: false,
[SomeStateEnum.Name]: 'John Doe',
};
function setState(key: SomeStateEnum, value: boolean | string) {
state[key] = value;
}