Skip to main content
InterviewHubPRO
Section Overview
Q12

Question 12 of 50

Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)

24%
TypeScript Master (50 Qs)•Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)

What is the `keyof` operator and Indexed Access types?

junior LevelMost AskedCode ExampleTypeScript

In Simple Words:

  • keyof T: Produces a union of all property keys of type T.
  • T[K] (Indexed Access): Extracts the type of a specific property K on type T.
typescript
interface User {
  id: string;
  name: string;
  age: number;
}

type UserKeys = keyof User; // "id" | "name" | "age"
type AgeType = User["age"]; // number

// Type-safe property getter
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
  return obj[key];
}