Merging interfaces
Unlike a type, an interface can be defined multiple times and will be treated as a single interface (all declarations will be merged), as shown in the following code block:
interface IUser {
username: string
email: string
name: string
age?: number
website: string
active: boolean
}
interface IUser {
country: string
}
const user: IUser = {
username: 'czantany',
email: '[email protected]',
name: 'Carlos Santana',
country: 'Mexico',
age: 35,
website: 'http://www.js.education',
active: true
}
This is very useful when you need to extend your interfaces in different scenarios by just redefining the same interface.