Keyof and Lookup Types
Discover how to extract and reference keys and properties from existing types, enabling dynamic and reusable type definitions.
Keyof and Lookup Types is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Introduction to Keyof and Lookup Types
The keyof and lookup types in TypeScript allow you to work dynamically with keys and properties of existing types.
They make your code more flexible and reusable by letting you reference and extract types from objects.

2
What is keyof?
The keyof operator creates a type consisting of all the keys of an object type.
Example:
type Person = {
name: string;
age: number;
};
type PersonKeys = keyof Person;3
What are Lookup Types?
Lookup types use square brackets [] to retrieve the type of a specific property of an object.
Example:
type Person = {
name: string;
age: number;
};
type NameType = Person['name'];4
Combining keyof and Lookup Types
You can use keyof and lookup types together to create dynamic and reusable type constraints.
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}5
Use Cases for keyof and Lookup Types
Common use cases include:
- Creating dynamic APIs.
- Type-safe property access in objects.
- Improving code flexibility with type constraints.
6
Practical Example
Here’s a practical example where we combine keyof and lookup types:
type User = {
id: number;
username: string;
};
function printKey<T, K extends keyof T>(obj: T, key: K): void {
console.log(`${key}: ${obj[key]}`);
}
const user: User = { id: 1, username: 'John' };
printKey(user, 'username');7
Benefits of Using keyof and Lookup Types
These features offer:
- Dynamic property access with type safety.
- Reusable and scalable code.
- Better error prevention at compile time.
8
9
Practice Task
Create a function using keyof and lookup types to access properties dynamically from a user object. Try it out!
10
Congratulations!
You’ve learned how to use keyof and lookup types to make your code dynamic and type-safe. Keep practicing to master these advanced features of TypeScript!

Frequently asked questions
Is the “Keyof and Lookup Types” lesson free?
Yes — the full text of “Keyof and Lookup Types” is free to read here on the web, and the TypeScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Keyof and Lookup Types”?
Discover how to extract and reference keys and properties from existing types, enabling dynamic and reusable type definitions. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Keyof and Lookup Types” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Keyof and Lookup Types
- Mapped Types
- Intersection and Union Types