第一种方案、使用[key: string]:string 形式为键名声明类型
声明类型:
interface FormInfoData {
[materialCode: string]: string
materialName: string
materialUnit: string
materialItem: string
materialOwnership: string
materialclassCode: string
materialclassName: string
materialSpecification: string
}
声明变量:
const formInfoData = reactive<FormInfoData>({
materialCode: '',
materialName: '',
materialUnit: '',
materialItem: '',
materialOwnership: '',
materialclassCode: '',
materialclassName: '',
materialSpecification: ''
})
使用遍历变量赋值:
Object.keys(formInfoData).forEach((prop: string) => {
formInfoData[prop] = prop in row ? row[prop] : ''
})
第二种方案、直接声明配置项
在tsconfig.json中compilerOptions里面新增忽略的代码,如下所示,添加后则不会报错
"suppressImplicitAnyIndexErrors": true