0Pricing
TypeScript Academy · Lesson

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

  1. Object types, optional/readonly, index signatures
  2. Interfaces vs Type Aliases
  3. Structural typing & excess property checks
← Back to TypeScript Academy