TypeScript Developer interview question · Most asked

Explain `keyof`, `typeof` (in type position) and indexed access types.

Summary

keyof T produces a union of T's property keys; typeof value (in a type position) gets the type of a runtime value; indexed access T[K] looks up the type of a property (or T[number] for array elements).

Longer Answer

Together they derive types from values: type Config = typeof config; type Key = keyof Config; type Value = Config[Key]. This keeps types in sync with runtime objects.

Key Points

  • keyof T → union of keys
  • typeof x → type of a value
  • T[K] and T[number] lookups
  • Derive types from values

More most-asked TypeScript Developer questions

← All TypeScript Developer questions