Find: Wrong Union Type
Find the Mistake Easy
Question
This code has a type error. Find the mistake:
Code
type ID = string | number;
const userId: ID = true;
Hint
Check what types are in the union vs what is being assigned.
Explanation
The type ID is string | number, but true is a boolean. Boolean is not in the union, so TypeScript errors: Type 'boolean' is not assignable to type 'string | number'. Fix: either add boolean to the union type or assign a string or number value.
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.