Loading
Turn cryptic stack traces into actionable fixes — the most underrated skill in programming.
The most important thing when you see an error: read it. Most beginners skip the error message and immediately Google the problem. But the error message itself usually tells you exactly what's wrong.
An error message has three parts:
Understanding the structure is half the battle.
| Error Type | Meaning | Common Cause |
| ------------------ | -------------------------------------- | -------------------------------------------------- |
| SyntaxError | Your code has a grammar mistake | Missing bracket, extra comma, typo |
| ReferenceError | You used a variable that doesn't exist | Typo in variable name, forgot to import |
| TypeError | You used a value the wrong way | Calling .map() on undefined, wrong argument type |
| RangeError | A number is outside the allowed range | Infinite recursion, invalid array length |
Example — ReferenceError:
Know the common error types by name.
The stack trace shows the call chain — the path your code took to reach the error. Read it from top to bottom:
Key rules:
node_modules lines)The top of the stack trace is where the error occurred.
TypeScript errors look different — they happen at compile time, before your code runs:
How to read them:
Button.tsx:12:5 means line 12, column 5Common TypeScript errors and fixes:
TypeScript catches errors before your code runs.
When you hit an error, follow this process every time:
undefined or null that shouldn't be?Pro tip: In VS Code, hover over red squiggly underlines to see the error message without even running your code.
Practice the 6-step workflow on your next error.
Look at each snippet and identify the error before running it:
Bug 1:
Bug 2:
Bug 3:
Spotting bugs by reading code is a skill that improves with practice.
What's next? Now that you can read errors, learn How to Use Git for Real Projects to save your work and collaborate with others.
TypeError: Cannot read properties of undefined (reading 'map')
at UserList (src/components/UserList.tsx:15:22)
at renderWithHooks (node_modules/react-dom/...)
at mountIndeterminateComponent (...)// ❌ This throws: ReferenceError: username is not defined
console.log(username);
// ✅ Fix: define the variable first
const username = "dustin";
console.log(username);Error: User not found
at findUser (src/lib/users.ts:42:11) ← error happened here
at getProfile (src/api/profile.ts:18:20) ← called by this
at handleRequest (src/server.ts:95:5) ← called by thissrc/components/Button.tsx:12:5
Type 'string' is not assignable to type 'number'.
12 count: "five",
~~~~~// ❌ Type 'string | undefined' is not assignable to type 'string'
const name: string = user?.name;
// ✅ Provide a fallback
const name: string = user?.name ?? "Anonymous";
// ❌ Property 'email' does not exist on type 'User'
// Fix: Check your interface definition — did you spell it right?
// ❌ Argument of type 'X' is not assignable to parameter of type 'Y'
// Fix: Check what the function expects vs. what you're passingconst users = [{ name: "Alice" }, { name: "Bob" }];
const names = users.map((user) => user.naem);
// What's wrong?function double(n: number): number {
return n * 2;
}
double("5");
// What error will TypeScript show?const data = JSON.parse("{ invalid json }");
// What error type is this?