Javascript TypeScript和Vue类-TS7053索引签名

Javascript TypeScript和Vue类-TS7053索引签名,javascript,typescript,vue.js,Javascript,Typescript,Vue.js,带有Vue类组件(和typescript)的Vue 2.6 实际代码: private validateField(fieldType: string, e: string) { this[fieldType] = e.length > 0 } 给出一个错误: TS7053:元素隐式具有“any”类型,因为“string”类型的表达式不能用于索引类型“index”。 在“index”类型上未找到具有“string”类型参数的索引签名 在我的情况下,建议使用什么方法添加签名?我要做的是

带有Vue类组件(和typescript)的Vue 2.6

实际代码:

private validateField(fieldType: string, e: string) {
  this[fieldType] = e.length > 0
}
给出一个错误:

TS7053:元素隐式具有“any”类型,因为“string”类型的表达式不能用于索引类型“index”。 在“index”类型上未找到具有“string”类型参数的索引签名


在我的情况下,建议使用什么方法添加签名?

我要做的是创建一个索引器界面:

interface ILookup<T> {
    [key: string]: T;
}
export default class App extends Vue implements ILookup<any> { 

    [index: string]: any;

    private validateField(fieldType: string, e: string) {
        this[fieldType] = e.length > 0
    }
}
我们得到以下(和其他)编译错误:

TS2411:类型为“Record”的属性“$attrs”不可用 可分配给字符串索引类型“boolean”

以及:

TS2411:类型为“Vue[]”的属性“$children”不可分配给 字符串索引类型为“boolean”


它与
(这与任何)[fieldType]
相同?不,我会说它不一样。因为通过使用
(thisaany)[fieldType]
可以将整个组件转换为
any
,在我的示例中,我只将索引器的返回类型声明为
any
。我用更多的信息更新了我的答案。
interface ILookup<T> {
    [key: string]: T;
}

export default class App extends Vue implements ILookup<boolean> { 

    [index: string]: boolean;

    private validateField(fieldType: string, e: string) {
        this[fieldType] = e.length > 0
    }
}