Guided Notes

Object Types & Type Aliases

Describing object shapes inline, optional and readonly properties, index signatures, type aliases, and excess property checks.

Object types

Slide 1 / 4

const patient: { name: string; age: number; ward?: string } = { name: "Neema", age: 34 };

β€’ Each property has a type. β€’ ? makes it optional β€” its type becomes string | undefined. β€’ Missing required properties and misspelled properties are errors.

TypeScript also infers object types: const car = { make: "Toyota", year: 2019 } has type { make: string; year: number }.

← Arrays & Tuples