Menu

Reading Compiler Errors and Using Your Editor

Lesson 5: Reading Compiler Errors and Using Your Editor

How do you read a TypeScript error?

Every error has the same parts:

src/cart.ts:14:22 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
Part Meaning
src/cart.ts:14:22 File, line, and column
TS2345 Error code: search it for explanations
Message What was expected and what was found

Read the message as "I expected X, but you gave Y". For long errors, read the last line first; it usually names the exact property that does not match.

Common errors

Code Message (short) Usual cause Fix
TS2322 Type 'X' is not assignable to type 'Y' Wrong value for a variable or property Change the value or the type
TS2345 Argument of type 'X' is not assignable Wrong argument to a function Pass the right type or convert it
TS2339 Property 'x' does not exist on type 'Y' Typo, or the type is too narrow Fix the name or update the type
TS2741 Property 'x' is missing in type Object lacks a required property Add it or make it optional
TS18048 'x' is possibly 'undefined' Value may not exist Check it first (Module 5)
TS7006 Parameter 'x' implicitly has an 'any' type Missing parameter annotation Add a type

Editor features to use

Feature How (VS Code) Use it to
Hover Move the mouse over a name See its inferred type
Go to definition F12 Jump to where a type is declared
Rename symbol F2 Rename everywhere safely
Quick fix Ctrl + . Add missing imports, properties, or annotations
Problems panel Ctrl + Shift + M See every error in the project

Example

type Customer = { id: string; name: string; email: string };

const asha: Customer = { id: 'c1', name: 'Asha R' };
// TS2741: Property 'email' is missing in type '{ id: string; name: string; }'
// but required in type 'Customer'.

The last part tells you exactly what to add: email.

Common mistakes

Mistake Effect Fix
Silencing errors with any or // @ts-ignore The bug is hidden, not fixed Fix the cause; use @ts-expect-error with a comment only when truly needed
Reading only the first line of long errors Missing the real cause Read from the bottom up
Fixing errors one by one in the terminal Slow Use the editor's Problems panel and quick fixes

Key takeaways

  • Errors say what was expected and what was found; the last line is often the most useful.
  • Hover, go to definition, and quick fixes are your fastest learning tools.

Try it: Create three deliberate errors (a typo, a missing property, a wrong argument type). Read each message, then fix them using quick fixes.


TypeScript Tutorial

J

Jebasta





Get in Touch For Details