I'm needing to update the value of a property of a class by a string property name. I started off by making sure the property name was valid via this method:
export class ClientDTO {
...
static isValidPropertyName(name: string): name is keyof ClientDTO {
return (name as keyof ClientDTO) !== undefined
}
}
And then in another class I'm doing this:
foo(key: string, newValue: string) {
if (!ClientDTO.isValidPropertyName(key)) {
return
}
if (newValue !== this.originalClient[key]) {
// @ts-ignore
this.originalClient[key] = newValue
}
}
The lookup works well now, but to do the update I'm having to put the // @ts-ignore
there and I'd really like to figure out how to do this properly without having to have the ignore there.
I have strict checkings turned on so I get the error
TS2322: Type 'any' is not assignable to type 'never'