0Pricing
TypeScript Academy · Lesson

The keyof Type Operator

Get a union of an object type's keys with keyof.

The Keys of a Type

The keyof operator takes an object type and produces a union of its property keys. It is the foundation for type-safe property access and generic key utilities.

Basic keyof

Apply keyof to an interface to get a union of its key names as string literal types.

interface User {
  id: number
  name: string
}
type UserKeys = keyof User // "id" | "name"
const k: UserKeys = "name"
console.log(k)

All lessons in this course

  1. The typeof Type Operator
  2. The keyof Type Operator
  3. Indexed Access Types
  4. Combining typeof and keyof
← Back to TypeScript Academy