In the code below typscript compiler shows error in update method, saying that 'any' is not assignable to type 'never'. I noticed that keyof type not working when the type contains boolean mixed with other types. How can I make it compile having mixed type values in the type?
type ConfigState = {
isAdminSet: boolean;
isDatabaseConnected: boolean;
adminName: string;
};
export class ConfigManager {
state: ConfigState = {
isAdminSet: false,
isDatabaseConnected: false,
adminName: "",
};
update(key: keyof ConfigState, value: ConfigState[keyof ConfigState]) {
this.state[key] = value;
}
}
But this compiles:
type ConfigState = {
isAdminSet: boolean;
isDatabaseConnected: boolean;
};
export class ConfigManager {
state: ConfigState = {
isAdminSet: false,
isDatabaseConnected: false,
};
update(key: keyof ConfigState, value: ConfigState[keyof ConfigState]) {
this.state[key] = value;
}
}