Q23: How do Indexed Access Types (`T[K]`) work?

Difficulty:MediumTopic:Type Lookup

An Indexed Access Type looks up specific sub-properties on another type using bracket notation syntax (Type[Key]).

Property Type Lookup
interface Order {
  id: string;
  customer: {
    name: string;
    address: { city: string };
  };
}

type CustomerType = Order["customer"]; // Type: { name: string; address: { city: string } }
type CityType = Order["customer"]["address"]["city"]; // Type: string
💡 Bracket notation pulls property types from complex nested object structures.
Key Takeaways
  • Look up property types dynamically from existing structural contracts.