Indexed access types reuse property and element types
Summary
An indexed access type such as RecordType["field"] retrieves a property type. The index is a type, so a literal-key union can retrieve a union of property types. [S1]
Details
keyof supplies the allowed keys of an object type. Combining it with indexed access can collect that object's property value types. For arrays, indexing the array type with number retrieves its element type. A missing property is a type error. A value variable is not itself a type-level key, though a suitable type alias can be used. [S1, S2]
Claims
- id: C1 claim: "Indexed access can retrieve a property type." source: S1 evidence: "look up a specific property on another type"
- id: C2 claim: "number can retrieve an array element type." source: S1 evidence: "using number to get the type of an array"
- id: C3 claim: "keyof produces a union of object keys." source: S2 evidence: "produces a string or numeric literal union of its keys"
Sources
- [S1] Indexed access types. Microsoft and TypeScript documentation contributors. https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html. CC-BY-4.0; license: https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE. Accessed 2026-11-05.
- [S2] Keyof type operator. Microsoft and TypeScript documentation contributors. https://www.typescriptlang.org/docs/handbook/2/keyof-types.html. CC-BY-4.0; license: https://raw.githubusercontent.com/microsoft/TypeScript-Website/v2/LICENSE. Accessed 2026-11-05.
Attribution and notices
This note is CC BY 4.0. Source material has been condensed and restated; short evidence excerpts retain their source license.
TypeScript Website documentation is CC BY 4.0. This is an original condensed explanation, not the original documentation.
License: CC-BY-4.0 · Original synthesis by iinventedlight, drafted by Librarian with AI assistance; based on the attributed sources
Cite this
Librarian. n.d.. "Indexed access types reuse property and element types." iinventedlight Library, iil:note:d67ez990. https://iinventedlight.com/library/notes/typescript-indexed-access-types/. License: CC-BY-4.0.
@misc{iil_note_d67ez990,
author = {{Librarian}},
title = {{Indexed access types reuse property and element types}},
howpublished = {iinventedlight Library},
url = {https://iinventedlight.com/library/notes/typescript-indexed-access-types/},
note = {Permanent ID iil:note:d67ez990. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/typescript-indexed-access-types.md.