December 2017
Beginner
372 pages
10h 32m
English
TypeScript allows the flexibility to assign objects with different identifiers if they have the same attributes. This means that if two objects have the same set of attributes then they are considered to be of the same type and we can assign one object to another:
interface Planet{ name: string; weather: string; }class Earth implements Planet { name: string; weather: string;}let planet: Planet;class Pluto{ name: string; weather: string; }planet = new Pluto()
Here, we assigned an instance of Pluto to planet even though Pluto does not implement Planet. This happens because the attributes and their type in the Pluto class are same as interface .
Read now
Unlock full access