Run ❯
Get your
own Node
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
// In TypeScript these would be interfaces with methods function makeSound(animal) { if ("bark" in animal) { // TypeScript knows animal is Dog here animal.bark(); } else { // TypeScript knows animal is Cat here animal.meow(); } } // Example usage const dog = { bark() { console.log("Woof woof!"); } }; const cat = { meow() { console.log("Meow!"); } }; makeSound(dog); // Outputs: Woof woof! makeSound(cat); // Outputs: Meow!
Woof woof! Meow!