Pick Type
Predict Output Easy
Question
What does this code print?
Code
type T = { a: number; b: string; c: boolean };
type P = Pick<T, "a" | "b">;
const x: P = { a: 1, b: "hi" };
console.log(x.a + x.b.length);
Hint
Pick selects only properties a and b.
Explanation
Pick<T, "a" | "b"> creates { a: number; b: string }. x is { a: 1, b: "hi" }. x.a is 1, x.b.length is 3. 1 + 3 = 4.
Related Resources
Related Lessons
- Utility Types
Learn utility types.
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.