0Pricing
TypeScript Academy · Lesson

Indexed Access Types

Look up property types with the T[K] syntax.

Looking Up Property Types

Indexed access types let you look up the type of a property using bracket syntax in a type position: Obj['prop']. It is like reading a value, but at the type level.

Basic Indexed Access

Index a type with a literal key to extract that property's type. User['name'] gives string.

interface User { id: number; name: string }
type NameType = User["name"] // string
const n: NameType = "Ada"
console.log(n)

All lessons in this course

  1. The typeof Type Operator
  2. The keyof Type Operator
  3. Indexed Access Types
  4. Combining typeof and keyof
← Back to TypeScript Academy