TypeScript · Types that pay for themselves

What are indexed access types?

Mediumindexed-accesstype-operatorskeyofUpdated Oct 2026
Quiz this track

Short answer

Indexed access types look up a property type with T[K], including array element types and nested paths. Combined with keyof, they keep property access and generics in sync.

An indexed access type is the type-level equivalent of reading a property. T["id"] is the type of the id property, and T[keyof T] is a union of all property types. This avoids duplicating a shape just to name one of its parts.

ts
type User = {
  id: number;
  profile: { name: string; age: number };
  tags: string[];
};

type Profile = User["profile"];
type Age = User["profile"]["age"];
type Tag = User["tags"][number];

Common patterns

  • T[K] with a generic key preserves the exact property type
  • T[keyof T] produces a union of all value types
  • ArrayType[number] extracts the element type
  • Nested paths such as T["a"]["b"] reach into object shapes
  • Tuple types can be indexed with a literal position

Indexed access is often paired with keyof in generic helpers. The key is constrained to keyof T, and the return type is T[K], so the compiler knows the result matches the requested property. That pattern is safer than returning a broad union or any.

Indexing with a key that does not exist is a type error. This is a feature: it catches misspelled property names before runtime.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1How do you get an array's element type?
  2. 2How does T[keyof T] differ from keyof T?
  3. 3Why combine indexed access with a generic key?
  4. 4Can you index a tuple by position?

Say it in the interview

Indexed access types look up a property type using T[K]. I use them to derive a nested type, such as the profile type from a user type, instead of duplicating the shape. For arrays, indexing with number gives the element type. Combined with keyof, indexed access keeps generic helpers precise and avoids unsafe casts.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live TypeScript mock interview and get scored feedback on depth, clarity and confidence.