TypeScript · Lesson 5 of 120
Reading Type Errors
What tsc tells you.
Type errors look scary at first, but they follow a simple pattern. The file, the line, and a sentence explaining what didn't fit.

- File
- Line
- What didn't fit
A wrong assignment
Bikes is a number. On line two, we try to put text into it. Run it. The error says line two, and that a string isn't assignable to a number.
app.tstypescript
let bikes: number = 12;
bikes = "twelve";
console.log(bikes);Output
app.ts line 2: Type 'string' is not assignable to type 'number'.
A misspelled name
Here we misspell the variable name. Run it. TypeScript can't find it, and even suggests the name we probably meant.
app.tstypescript
const stockCount: number = 12;
console.log(stokCount);Output
app.ts line 2: Cannot find name 'stokCount'. Did you mean 'stockCount'?
Reading any error
Start with the line number. Read the sentence slowly, it usually says this type isn't assignable to that type. Look at both types. And fix the value, or the type, whichever is wrong.
| key | value |
|---|---|
| First | the line number |
| Then | the sentence |
| Compare | the two types |
| Fix | value or type |
Summary
Every type error gives a line, and a sentence about what didn't fit. Next, type inference.
Key takeaways- Line number
- Assignable
- Did you mean
Next up: Type Inference — TypeScript works it out