Predict Mapped Type Output
Predict Output Medium
Question
What does this code print?
Code
type Stringify<T> = { [K in keyof T]: string };
interface Point { x: number; y: number; }
const labeled: Stringify<Point> = { x: "horizontal", y: "vertical" };
console.log(labeled.x);
console.log(labeled.y);
Hint
Stringify converts all property types to string, but values are set manually.
Explanation
The mapped type Stringify<Point> creates a type { x: string; y: string }. The object labeled assigns "horizontal" to x and "vertical" to y. The output is horizontal and vertical on separate lines.
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.