Slide 17
Slide 17 text
• TypeScript is JavaScript.
• Interface is only a TypeScript compiler concept (type checking).
• Sometime you have to deal with the any type (Example: third part).
• The Duck example:
const duck = {
fly: () => console.log("I can fly!"),
swim: () => console.log("I can swin!"),
feather: true
};
const penguin = {
swim: () => console.log("I can swin!"),
feather: true
};
const isDuck = (obj: any) => (obj.hasOwnProperty("feather")
&& obj.fly
&& obj.swim);
if(isDuck(duck)) {
(duck).fly();
}
if(!isDuck(penguin)) {
console.log("Penguin can't fly...")
}