Read TypeScript Compiler Errors

TypeScript error messages are precise and structured. Learn to read the error format, understand the most common error codes, and fix each one quickly.

6 min read

TypeScript compiler errors follow a consistent format. Once you know how to read them, fixing them becomes fast. Every error tells you three things: where the problem is, what the problem is, and what TypeScript expected instead.

Here is a typical error:

texttext
app.ts:5:10 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.

Breaking it down:

PartMeaning
app.tsThe file with the error
:5Line number
:10Column (character position on that line)
TS2345Error code (unique identifier)
The sentence after the codePlain-English description of the problem

The error code is useful for searching, but the sentence usually tells you everything you need. Let's look at the errors you will see most often.

The Error Format in Detail

When you compile a file with tsc, the terminal shows the exact error together with the surrounding source code, not just a bare message. Here is a small file with a type mistake:

typescripttypescript
// app.ts
function double(n: number): number {
  return n * 2;
}
 
const result = double("hello");

Save the file, then compile it from the terminal exactly the way you normally would when running any TypeScript file:

bashbash
tsc app.ts

The compiler prints the file, the exact position, the error code, and a snippet of the offending line with a marker under the problem:

texttext
app.ts:5:22 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
 
5 const result = double("hello");
                       ~~~~~~~

The compiler shows the exact line with a squiggly underline under the problematic part. The underline points to "hello" because that is the argument with the wrong type. This visual marker makes it easy to spot the issue even in longer lines.

Most Common Error Codes

Here are the errors you will encounter most often as a beginner.

TS2345: Wrong Argument Type

You passed a value whose type does not match the parameter type.

typescripttypescript
function printLength(text: string) {
  console.log(text.length);
}
 
printLength(42);

Compiling this reports the mismatch immediately, pointing at the call that passed the wrong type, instead of letting it reach runtime:

texttext
error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

Fix: pass a string, or convert the number to a string with String(42) or 42.toString().

TS2339: Property Does Not Exist

You tried to access a property that the type does not have.

typescripttypescript
const user = { name: "Alex", age: 28 };
console.log(user.email);

TypeScript checks the object's shape and reports exactly which property is missing, right down to a spelling suggestion when one is available:

texttext
error TS2339: Property 'email' does not exist on type '{ name: string; age: number; }'.

Fix: check your spelling, or add the property to the type. The error often suggests the correct name if you made a typo.

TS18047 / TS2531: Possibly Null or Undefined

You tried to use a value that might be null or undefined without checking first.

typescripttypescript
function getLength(text: string | null) {
  return text.length;
}

The compiler will not let this compile until you prove the value cannot be null, and reports exactly that at the line in question:

texttext
error TS18047: 'text' is possibly 'null'.

Fix: add a null check before using the value, so the compiler can prove it is safe at that point in the code:

typescripttypescript
function getLength(text: string | null) {
  if (text === null) return 0;
  return text.length;  // Safe now
}

TS2554: Wrong Number of Arguments

You called a function with too few or too many arguments. TypeScript knows the exact parameter list for every function, so it checks the call site against it every time.

typescripttypescript
function multiply(a: number, b: number) {
  return a * b;
}
 
multiply(5);

The compiler counts the arguments at every call site and reports the exact expected and actual counts when they do not match:

texttext
error TS2554: Expected 2 arguments, but got 1.

Fix: pass the correct number of arguments, or make the parameter optional with b?: number.

TS2322: Wrong Assignment Type

You tried to assign a value to a variable or property of a different type.

typescripttypescript
let age: number = 25;
age = "twenty-five";

Once a variable has an inferred or annotated type, TypeScript enforces it on every later assignment and reports a mismatch immediately:

texttext
error TS2322: Type 'string' is not assignable to type 'number'.

Fix: assign a number, or change the variable's type annotation.

TS18048: Possibly Undefined in an Object

You accessed a property on something that might be undefined.

typescripttypescript
type User = { name: string } | undefined;
 
function getName(user: User) {
  return user.name;
}

This works the same way as the null check earlier, except the value here is a union that includes undefined instead:

texttext
error TS18048: 'user' is possibly 'undefined'.

Fix: check that the value exists before accessing its properties.

Fix Errors Top to Bottom

When you have multiple errors, fix the first one. Later errors are often caused by the first one, not by independent problems.

typescripttypescript
function getUser(id: number) {
  return { name: "Alex", id };
}
 
const user = getUser("abc");          // Error 1: string is not number
console.log(user.name.toUpperCase()); // Error 2: user might be undefined
console.log(user.email);              // Error 3: email doesn't exist

Compiling this file all at once produces three errors, though only the first one is the real root cause to fix:

texttext
app.ts:5:25 - error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.
app.ts:6:21 - error TS18048: 'user' is possibly 'undefined'.
app.ts:7:21 - error TS2339: Property 'email' does not exist on type '{ name: string; id: number; }'.

Error 2 and 3 are real, but they might disappear after fixing Error 1 if the function return type inference changes. Always fix from the top. After changing "abc" to 1, recompile and see which errors remain.

Errors in the Editor vs the Terminal

In VS Code, TypeScript errors appear as red squiggly lines as you type. These are the same errors tsc would report. The editor shows them faster because the TypeScript language server runs continuously in the background.

If you see errors in VS Code that tsc does not report, check:

  • The TypeScript version in VS Code's status bar. It might differ from your global tsc.
  • Whether your tsconfig.json is in the project root. VS Code looks for it there.
  • Whether you have strict: true in your tsconfig. VS Code uses your config settings.

Errors You Can Safely Ignore (Sometimes)

Not every error means your code is broken. Some are style preferences or strictness choices.

noUnusedLocals (TS6133): a variable is declared but never used. This is a warning that helps you clean up dead code. It does not mean your logic is wrong.

noImplicitAny (TS7006): a parameter has no type annotation and TypeScript cannot infer it. This is a reminder to add types, not a bug. In a quick script, you might leave it. In production code, add the annotation.

These checks are enabled by strict: true. You can disable individual checks in your tsconfig if they get in the way, but keeping them on produces better code.

For a full walkthrough of strict mode options, see TypeScript compiler explained. To learn how to set up a complete project, see TypeScript project setup for beginners.

Rune AI

Rune AI

Key Insights

  • Every TypeScript error has a location, a code, and a plain-English description.
  • TS2345 means you passed the wrong type to a function. TS2339 means a property does not exist.
  • TS18047 means a value might be null and you need to check it first.
  • Read the error from top to bottom. The first error is often the real cause of later errors.
  • Use --noEmitOnError to prevent JavaScript output when type errors exist.
RunePowered by Rune AI

Frequently Asked Questions

Why does TypeScript show errors but still produce JavaScript output?

By default, tsc emits JavaScript even when there are type errors. This is so you can run partially-migrated code. Use `--noEmitOnError` to prevent output when errors exist.

What does the TS error code mean?

Every TypeScript error has a code like TS2345 or TS18048. You can search the code online for a detailed explanation, but the error message itself is usually clear enough to understand the problem.

Why do I get errors in my editor but not when I run tsc?

Your editor may be using a different version of TypeScript or different tsconfig settings. Check the TypeScript version in VS Code's status bar and make sure your tsconfig.json is in the project root.

Conclusion

TypeScript error messages follow a consistent format: file location, error code, and a plain-English description of what is wrong. The most common errors are type mismatches (TS2345), missing properties (TS2339), possibly-null values (TS18047), and missing arguments (TS2554). Read the message, look at the line it points to, and the fix is usually clear. The compiler tells you what it expected and what it got. Trust it.