Find: Wrong Conditional Type
Find the Mistake Medium
Question
This code has a type error. Find the mistake:
Code
type NonNullable<T> = T extends null | undefined ? never : T;
const x: NonNullable<string | null> = null;
Hint
What does NonNullable resolve to for string | null?
Explanation
NonNullable<string | null> distributes over the union: string resolves to string, null resolves to never. The result is string (never is dropped). Assigning null to a string type errors: Type 'null' is not assignable to type 'string'. Fix: assign a string value like "hello".
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.