I know that interfaces in typescript allow us to merge different types. When i tried to do so, i am getting error while transpiling the script.
Here is my buggy interface
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
}
}
I am getting this error on transpiling ts script
Subsequent property declarations must have the same type. Property 'type' must be of type '"webhook"', but here has type '"buylink"'.
PS: I have seen many libraries (for example: nodemailer, inquirer) are loading typings based on some flag or condition.