Skip to content

    ↑↓ move · ⏎ open · esc close

    Operators

    T[K]

    Reads a property type back out of an object type.

    What it is

    The other half of `keyof`. It takes a key type — not a key *name*, a type — which is why it can be handed a union and answer with a union. That single fact is what lets `T[keyof T]` mean "all the value types" without any iteration.

    Examples

    • User['id']
      number
    • User['id' | 'name']
      string | number
    • User[keyof User]
      string | number | boolean

      Every value type at once, and the reason you almost never need to iterate to collect them.

    Each resolved type above was printed by TypeScript 5.9.3, not written by hand.

    What it does not do

    • It does not use dot notation. `User.id` is not a type — indexed access is always written with brackets and a key *type*, so `User["id"]` with quotes.
    • It does not tolerate a key it cannot verify. Indexing by an unconstrained type parameter is TS2536, and the fix is a constraint rather than a cast.

    Takeaway

    `T[number]` on a tuple or array gives you the element type, which is the same trick applied to a numeric key set. It is the single most useful indexed access there is.