Node.js 如何将值传递给TypeScript中在函数参数中传递名称的属性?
我收到eslint/typescript错误:Node.js 如何将值传递给TypeScript中在函数参数中传递名称的属性?,node.js,typescript,eslint,Node.js,Typescript,Eslint,我收到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&q
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
}
它会工作得很好。这个
有一个类似[index:string]:string代码>?@Anatoly nevermind,我有一个问题的快速解决方案