type TTest = {
id: number,
name: string,
code: string,
siteId: number,
}
type TTest2 = {
id: number,
create_time: string,
update_time: string,
name: string,
code: string,
siteId: number,
siteName: string
}
const testForm = ref<TTest>({
id: 0,
name: '',
code: '',
siteId: 0
})
const update = (row: TTest2) => {
let key: keyof TTest
for(key in editForm.value) {
testForm.value[key] = row[key]
}
}
以上testForm.value[index]
赋值为什么ts报错:*不能将类型“string | number”分配给类型“never”。
不能将类型“string”分配给类型“never”。ts(2322)*
let key: keyof TTest对key类型做了约束,不理解为什么会报错