Let’s resolve this forever outstanding question:
Should I use type
or interface
?
Spoiler: It’s called “TypeScript” not “InterfaceScript” 😉
Why a resolution is needed?
Typescript documentation is itself vague about which one should be used. However, vagueness is not helpful while creating a reliable software.
Most programming languages contain good parts and bad parts. I discovered that I could be a better programmer by using only the good parts and avoiding the bad parts. After all, how can you build something good out of bad parts?
Douglas Crockford
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to do it.
Zen of Python
type – Good, interface – Bad
1. interface
is mutable
Redeclaring an interface appends to existing definition:
interface MyInterface {
name: string
}
interface MyInterface {
phone: number
}
let variable : MyInterface = {
name: '
[gs-fb-comments]