Interface is a powerful way to define the shape of an object. It sets a "contract" for exactly which properties and methods an object must have.
typescript
interface User {
name: string;
id: number;
is_admin?: boolean; // Optional property
}
function printUser(user: User) {
console.log(`User: ${user.name} (ID: ${user.id})`);
}
let myUser: User = { name: "Alice", id: 123 };
printUser(myUser);You should see
User: Alice (ID: 123)