Unit 4
Unit 4
Interfaces in TypeScript
Interfaces define properties, methods, and events, which are the members of the interface.
Duck Typing is a dynamic typing style used in TypeScript, where the type of an object is determined
by its present properties or methods, not by its name or inheritance.
If an object "walks like a duck and quacks like a duck", it’s considered a duck.
This means:
If an object has all the required properties and methods, it is treated as that interface, even if it's
not explicitly using the interface.
interface Person {
firstName: string;
lastName: string;
let myObj = {
firstName: "Steve",
lastName: "Rogers",
age: 25
Even though myObj has an extra property age, it is accepted as Person type because it has both
firstName and lastName — this is duck typing.