Typescript类型通过字符串属性名称安全更新属性

我需要通过字符串属性名称来更新类的属性的值。我首先通过以下方法确保属性名称有效:

export class ClientDTO {
    ...

    static isValidPropertyName(name: string): name is keyof ClientDTO {
        return (name as keyof ClientDTO) !== undefined
    }
}

然后在另一堂课中,我正在这样做:

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.

我已经进行了严格的检查,所以我得到了错误

TS2322:类型“ any”不能分配给类型“ never”