Find: Incorrect Mapped Type
Find the Mistake Medium
Question
This code has a type error. Find the mistake:
Code
type Getter<T> = { [K in keyof T]: () => T[K] };
interface Point { x: number; y: number; }
const getters: Getter<Point> = { x: () => "hello", y: () => 5 };
Hint
Check the return types of the getter functions against the mapped type.
Explanation
The mapped type Getter<Point> expects x: () => number and y: () => number, but the object provides x: () => string (returns "hello"). TypeScript errors: Type 'string' is not assignable to type 'number'. Fix: make the x getter return a number: x: () => 10.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.