1,定义对象后扩展对象属性报错

报错详情:Property 'id' does not exist on type 'query'.Vetur(2339)

例如:

let query = {name: 'aa'}
if (id) {
    query.id = id // Property 'id' does not exist on type 'query'.Vetur(2339)
}

解决方法,添加代码:

interface queryObject {
    name: String
    [prop: string]: any
}
let query: queryObject  = {name: 'aa'}
if (id) {
    query.id = id
}

Jaywin
265 声望16 粉丝

一些花开在高高的树上,一些果结在深深的地下。ณۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗณۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗۗ...