Find: Missing Type Guard
Find the Mistake Medium
Question
This code has a type error. Find the mistake:
Code
function process(value: string | number) {
return value.toUpperCase();
}
Hint
Not all types in the union have toUpperCase.
Explanation
The method toUpperCase() does not exist on number. Since value is string | number, TypeScript only allows methods common to both types. Fix: add a type guard to narrow the type: if (typeof value === 'string') return value.toUpperCase(); before calling string-only methods.
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.