如何将值传递给 属性 该名称是在 TypeScript 的函数参数中传递的?

How to pass value to property that name was passed in function parameter in TypeScript?

我收到 eslint/typescript 错误:

errorUnsafe member access .value on an any value
@typescript-eslint/no-unsafe-member-access  

当我尝试将值保存到动态 属性 名称时:

selectChange(name: string, value: string) {
    if(this[name] && typeof this[name].value === "string") {
      this[name].value = value
    }
  }

我添加了 if 语句,但没有用,是否可以以正确的方式进行?或者我必须更改eslint配置文件。

好的,我有解决办法:

在上面某处声明:

type column = 'property1' | 'property2'

并从方法中删除不必要的 if 语句:

selectChange(name: column, value: string) {
    this[name].value = value
}

它将完美运行。