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[]”
*/
}
}
我想重置 formData,ts 抛出错误form[key] = initialValue
。
我想要正确的语法覆盖值