Recall & Review
beginner
What is a conditional type in TypeScript?
A conditional type chooses one type or another based on a condition. It uses syntax like
T extends U ? X : Y, meaning if T fits U, use X, else use Y.Click to reveal answer
beginner
How do generics work with conditional types?
Generics let you write flexible types that depend on input types. When combined with conditional types, you can create types that change based on the generic type passed in.Click to reveal answer
beginner
Explain this TypeScript type:
type IsString<T> = T extends string ? true : false;This type checks if
T is a string. If yes, it becomes true, otherwise false. For example, IsString<string> is true, but IsString<number> is false.Click to reveal answer
intermediate
What happens if you use a union type with a conditional type?
Conditional types distribute over union types. For example,
IsString<string | number> becomes IsString<string> | IsString<number>, which is true | false.Click to reveal answer
beginner
Why use conditional types with generics?
They let you create smart types that adapt based on input types. This helps catch errors early and makes your code more flexible and clear.Click to reveal answer
What does this conditional type do?
type Check<T> = T extends number ? 'Number' : 'Other';✗ Incorrect
The type checks if T fits number. If yes, it returns 'Number', otherwise 'Other'.
What is the result of
Check<string> if Check<T> = T extends number ? 'Number' : 'Other'?✗ Incorrect
Since string does not extend number, the result is 'Other'.
How do conditional types behave with union types like
T = string | number?✗ Incorrect
Conditional types distribute over unions, applying the condition to each member.
Which syntax correctly defines a conditional type?
✗ Incorrect
Conditional types use the syntax
T extends U ? X : Y.What is the benefit of using conditional types with generics?
✗ Incorrect
Conditional types with generics create flexible types that adapt based on input types.
Explain how conditional types work with generics in TypeScript.
Think about how you can check if a generic type fits another type and return different types.
You got /4 concepts.
Describe what happens when a conditional type is used with a union type generic.
Remember how unions split the conditional check for each type inside.
You got /3 concepts.