【发布时间】:2018-09-11 15:18:20
【问题描述】:
尝试解构form.elements 对象时出现以下错误:
类型“HTMLFormControlsCollection”没有属性“x”,也没有字符串索引签名
// in a class
domRefs: {[key: string]: HTMLFormElement | null} = {
myForm: null
}
onButtonClick = () => {
console.debug(this.domRefs.myForm!.elements) // screenshot below
const {a, b, c} = this.domRefs.myForm!.elements
}
我不想使用不会发出此错误的: any 类型注释。
【问题讨论】:
-
我相信你很久以前就已经解决了 - 但只是为了其他读者的利益 - 像往常一样,罪魁祸首是标准定义库的限制,除了扩充之外别无他法
HTMLFormControlsCollection接口。
标签: typescript index-signature typescript-lib-dom