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 keystypeof x→ type of a valueT[K]andT[number]lookups- Derive types from values
More most-asked TypeScript Developer questions
- Explain `any`, `unknown` and `never`.
- What are the differences between `interface` and `type` aliases?
- What is structural typing in TypeScript?
- What is type narrowing and what techniques does TypeScript support?
- What are discriminated unions and why are they powerful?
- What are generics and how do constraints work?
- Which built-in utility types do you use most, and what do they do?
- What is TypeScript and what problems does it solve?