Challenge - 5 Problems
Extract Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Extract type example?
Consider the following TypeScript code using the Extract utility type. What is the type of
Result?Typescript
type A = 'apple' | 'banana' | 'cherry'; type B = 'banana' | 'dragonfruit'; type Result = Extract<A, B>; // What is the type of Result?
Attempts:
2 left
💡 Hint
Extract keeps only the types that are in both sets.
✗ Incorrect
The Extract type keeps only the types that are assignable to both A and B. Since only 'banana' is common, Result is 'banana'.
❓ Predict Output
intermediate2:00remaining
What is the output type of Extract with object types?
Given these types, what is the type of
Selected after using Extract?Typescript
type Fruit = { name: string; color: string } | { name: string; taste: string };
type SweetFruit = { name: string; taste: string };
type Selected = Extract<Fruit, SweetFruit>;
// What is Selected?Attempts:
2 left
💡 Hint
Extract picks types from the first union that are assignable to the second.
✗ Incorrect
Only the type { name: string; taste: string } from Fruit matches SweetFruit, so Selected is that type.
❓ Predict Output
advanced2:00remaining
What is the type of Z when Extract has no overlapping types?
Look at this code snippet. What is the type of
Z?Typescript
type X = string | number;
type Y = boolean;
type Z = Extract<X, Y>;
// What is Z?Attempts:
2 left
💡 Hint
Extract returns never if no types overlap.
✗ Incorrect
Extract returns never if there is no overlap between the two types. No error occurs.
❓ Predict Output
advanced2:00remaining
What is the type of Result after extracting keys from an interface?
Given this interface and Extract usage, what is the type of
Result?Typescript
interface Person {
name: string;
age: number;
location: string;
}
type Keys = keyof Person;
type Result = Extract<Keys, 'age' | 'location' | 'email'>;
// What is Result?Attempts:
2 left
💡 Hint
Extract picks keys common to both sets.
✗ Incorrect
Keys are 'name' | 'age' | 'location'. Extract keeps only keys also in 'age' | 'location' | 'email', so Result is 'age' | 'location'.
🧠 Conceptual
expert2:00remaining
Which option best describes the Extract utility type behavior?
Select the statement that correctly describes what the Extract utility type does in TypeScript.
Attempts:
2 left
💡 Hint
Think about which types from T remain after Extract.
✗ Incorrect
Extract keeps only those types from T that can be assigned to U, filtering T by U.