我知道打字稿中的接口允许我们合并不同的类型。当我尝试这样做时,我在编译脚本时遇到了错误。
这是我的错误界面
export interface StoreConfig extends Document, TimeStamps {
type: 'webhook'
metadata: {
endpoint: string
method: HttpMethod
secret: string
event: string | string[]
}
}
export interface StoreConfig extends Document, TimeStamps {
type: 'buylink'
metadata: {
prodId: string
key: string
expire: Date
}
}
export interface StoreConfig extends Document, TimeStamps {
type: 'paymentmethod'
metadata: {
apiKey: string
mode: string
whsecret: string
}
}
我在转换 ts 脚本时收到此错误
Subsequent property declarations must have the same type. Property 'type' must be of type '"webhook"', but here has type '"buylink"'.
PS:我看到许多库(例如:nodemailer、inquirer)正在加载基于某些标志或条件的类型。