I seem to be experiencing an issue with the Typescript compiler in this particular case, despite my belief that there shouldn't be any problem
type Car = {
isOn: boolean
name: string
}
function doSomething(key: keyof Car, value: string | boolean) {
const car: Car = {
isOn: false,
name: "myCar",
}
if (typeof car[key] === typeof value) {
car[key] = value
}
}
Error Message:
"TS2322: Type 'string | boolean' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'."
Do you see where I might have gone wrong?