Interfaces allow you to define the structure of objects. You can extend an interface from another interface to build a new interface that inherits properties from the base interface. This promotes code reuse and allows you to create more specialized interfaces while maintaining a consistent structure.
interface BasicAddress {
name?: string;
street: string;
city: string;
country: string;
postalCode: string;
}
interface AddressWithUnit extends BasicAddress {
unit: string;
}
- In this example,
AdminUser
is an intersection type that combines properties from bothAdmin
andUser
types.