function resetForm () {
// const INITIALFORM = {
// url: '',
// device: 'mobile',
// dimension: ['time', 'page'],
// }
for (const key in INITIALFORM) {
type KeyType = keyof typeof INITIALFORM
const initialValue = INITIALFORM[key as KeyType]
// ^ const initialValue: string | string[]
form[key as KeyType] = initialValue
/**
* type KeyType = "url" | "device" | "dimension"
不能将类型“string | string[]”分配给类型“string & string[]”。
不能将类型“string”分配给类型“string & string[]”。
不能将类型“string”分配给类型“string[]”
*/
}
}
i want to reset formData, ts throw error at form[key] = initialValue
.
I desire the correct syntax override value