Conditional types select types through assignability. A conditional over a naked type parameter distributes across union members.
Before you start
You should be comfortable with JavaScript values, functions and objects. Use a TypeScript project with strict checking enabled when trying the examples. Separate what the compiler proves from what must still be checked when values arrive at runtime.
The practical goal is to reason through this situation: A wrapper type applied to string or number can produce separate wrappers for each member. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: State the type-level question
A conditional asks whether one type is assignable to another. It does not execute an if statement on runtime data.
Step 2: Check union distribution
When the checked side is a naked type parameter, the conditional is applied to each union member separately.
Step 3: Disable distribution when needed
Wrap the checked types in tuples to ask about the entire union. Choose the form matching the requirement rather than relying on an accidental result.
Worked scenario
A wrapper type applied to string or number can produce separate wrappers for each member.
type IsText<T> = T extends string ? true : false;
type AllText<T> = [T] extends [string] ? true : false;
type A = IsText<string | number>; // true | false
type B = AllText<string | number>; // false
type C = AllText<'a' | 'b'>; // trueA considers each member independently. B asks whether the whole union can be assigned to string, which number prevents. C succeeds because both literals are strings.
Common mistake
Wrapping the checked type in a tuple changes distribution behavior.
Verify the behavior
Inspect the three aliases, then test never and unknown separately. Special types can produce unintuitive results; confirm the intended public contract with type fixtures.
Interview exercise
Test the entire union together.
Answer and reasoning
Use a non-distributive tuple comparison when the requirement concerns the union as a whole.
Continue learning
Compare the scenario with the TypeScript interview questions and test your understanding with the TypeScript MCQs. For terminology and implementation details, consult the reference material.