Object types, optional/readonly, index signatures
Define object types with properties, mark some as optional or readonly, and use index signatures for flexible keys.
Intro
Goal: Define structured objects in TypeScript. You will explore object types, optional properties, readonly modifiers, and index signatures for dynamic keys.
Basic object
Object types define property names and their types. Every object must satisfy the declared structure.
type User = {
id: number;
name: string;
};
const u: User = { id: 1, name: "Ada" };
console.log(u);All lessons in this course
- Object types, optional/readonly, index signatures
- Interfaces vs Type Aliases
- Structural typing & excess property checks