So I've been exploring interfaces in TypeScript and their ability to merge different types, but I ran into a hiccup while transpiling my script.
Here's where things went wrong in my 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
}
}
Upon transpiling the TypeScript script, I received the following error:
Subsequent property declarations must have the same type. Property 'type' must be of type '"webhook"', but here has type '"buylink"'.
On a side note, I've noticed that some libraries (like nodemailer and inquirer) load typings based on certain conditions or flags.