

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Interfaces
incomplete
2: Extending Interfaces
incomplete
3: Extending Multiple Interfaces
incomplete
4: Overriding Interface Properties
incomplete
5: Declaration Merging
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
This is the exception to my previous rule of thumb that "you should prefer type over interface". Interfaces are a bit better when it comes to extending other interfaces (inheriting properties).
With types, you use the & (intersection) operator to extend types:
type Character = {
name: string;
level: number;
};
type Wizard = Character & {
spellbook: string[];
mana: number;
};
With interfaces, you use the extends keyword:
interface Character {
name: string;
level: number;
}
interface Wizard extends Character {
spellbook: string[];
mana: number;
}
In both cases, a Wizard now has all four properties: name, level, spellbook, and mana.
To quote Microsoft's wiki:
Interfaces create a single flat object type that detects property conflicts, which are usually important to resolve! Intersections on the other hand just recursively merge properties, and in some cases produce
never. Interfaces also display consistently better, whereas type aliases to intersections can't be displayed in part of other intersections. Type relationships between interfaces are also cached, as opposed to intersection types as a whole. A final noteworthy difference is that when checking against a target intersection type, every constituent is checked before checking against the "effective"/"flattened" type.For this reason, extending types with interfaces/extends is suggested over creating intersection types.
Put simply, with interfaces the developer ergonomics are a bit better and compilation is a bit faster.
Support.ai handles different types of messages, like emails and text messages, but all messages share some common structure.
TextMessage:
text - stringcarrier - stringEmailMessage
subject - stringbody - string