— Typescript, Type, Interface — 1 min read
1interface Animal {2 name: string;3}45interface Bear extends Animal {6 honey: boolean;7}89const bear = getBear();10bear.name;11bear.honey;
1interface Animal {2 name: string;3}45interface Bear extends Animal {6 honey: boolean;7}89const bear = getBear();10bear.name;11bear.honey;
1interface Bear {2 name: string;3}45interface Bear {6 honey: boolean;7}89const bear: Bear = {10 name: "teddy",11 honey: true,12};1314console.log(bear);1516// [LOG]: {17// "name": "teddy",18// "honey": true19// }
1type Bear = {2 name: string;3};45type Bear = {6 honey: boolean;7};89// Error: Duplicate identifier 'Bear'.
1type SomeNumber = number;2interface MyNumber {3 number: number;4}56interface SomeType extends number {} // X
1interface Mammal {2 name: string;3}45function echoMammal(m: Mammal) {6 console.log(m.name);7}89echoMammal({ name: 12343 }); // Error: (property) Mammal.name: string1011type MammalType = { name: string };12function echoAnimal(m: MammalType) {13 console.log(m.name);14}1516echoAnimal({ name: 12345 }); // Error: (property) name: string