

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
Okay, so here's the quirk that makes me recommend type over interface in most cases. Declaration merging is, in my experience, mostly a footgun. Sure, it's useful in certain niche cases (like modifying the global Window type in front-end code), but most of the time it leads to confusing bugs.
When you declare the same interface (use the same name) multiple times, all the declarations are merged. This:
interface Spaceship {
name: string;
}
interface Spaceship {
engines: number;
}
interface Spaceship {
lightSpeed: boolean;
}
Is the same as this:
interface Spaceship {
name: string;
engines: number;
lightSpeed: boolean;
}
If you use the type keyword instead, you'll get an error that you can't redeclare the type (which is probably what you want):
type Spaceship = {
name: string;
};
// Duplicate identifier 'Spaceship'
type Spaceship = {
engines: number;
};