interface
Defines the shape of an object type. Interfaces are open (can be extended with declaration merging) and are erased at runtime.
Syntax
typescript
interface Name {
property: type;
optionalProp?: type;
method(param: type): returnType;
}Example
typescript
interface User {
id: string;
name: string;
email: string;
role?: "admin" | "user";
}
function greet(user: User): string {
return `Hello, ${user.name}`;
}