Demo mode — data resets on refresh.
Types and Interfaces
Interfaces vs Types
Interfaces
Interfaces define the shape of an object. They're the main way to name object types in TypeScript.
interface User { name: string; age: number; email?: string }
The ? makes a property optional. Interfaces support declaration merging — you can reopen them to add more properties.
Type Aliases
Type aliases (type keyword) can name any type, including unions, intersections, and primitives. They cannot be reopened.
When to Use Which
Use interfaces when defining object shapes, especially for public APIs and class contracts. Use type aliases for unions, intersections, mapped types, and non-object types.
Knowledge Check
1.How do you mark an interface property as optional?
2.Can type aliases be re-opened after declaration?