All Articles

Intro To TypeScript Performance

Matt Pocock
Matt PocockMatt is a well-regarded TypeScript expert known for his ability to demystify complex TypeScript concepts.

You'll often find folks talking about "TypeScript Performance". They might say "my codebase feels slow" and that "TypeScript is making my editor slow".

What do they mean?

What is TypeScript Performance?

TypeScript performance is a measure of how fast TypeScript can type-check your codebase. It's a measure of how quickly your editor can provide feedback on your code.

It's NOT a measure of how fast your code runs. TypeScript is a compile-time tool, not a runtime tool. Simply using TypeScript will not change the speed at which the emitted JavaScript runs - TypeScript doesn't do anything at runtime.

What Does Bad TypeScript Performance Look Like?

When TypeScript performance is poor, you will notice:

  • Your editor is slow to provide feedback on your code.
  • Your editor is slow to autocomplete.
  • Your builds take a long time to complete.

In other words, the things you do every day become slower and more painful.

What Causes Bad TypeScript Performance?

TypeScript performance can be affected by several factors.

The first is scale. Simply put, the more code TypeScript needs to check at once, the slower it will run. However, scale is often less of a factor than you might think.

The second factor is the way you write your code. Using intersections instead of interfaces, utilizing project references, and employing return types judiciously are all useful ways to address TypeScript performance issues.

The TypeScript Performance Wiki provides a great list of strategies you can use to improve your TypeScript performance.

How Do You Measure TypeScript Performance?

You can use some tsc flags to measure your TypeScript performance.

Using tsc --diagnostics or tsc --extendedDiagnostics will provide you with information about how long it takes TypeScript to type-check your codebase.

By running tsc --generateTrace ./outDir, you can generate a trace file that can be opened in Chrome's Trace Viewer to see where TypeScript is spending its time.

Aleksandra Sikora's excellent talk at BeJS is a great resource to begin exploring this topic.

Matt's signature

Share this article with your friends

`any` Considered Harmful, Except For These Cases

Discover when it's appropriate to use TypeScript's any type despite its risks. Learn about legitimate cases where any is necessary.

Matt Pocock
Matt Pocock

No, TypeScript Types Don't Exist At Runtime

Learn why TypeScript's types don't exist at runtime. Discover how TypeScript compiles down to JavaScript and how it differs from other strongly-typed languages.

Matt Pocock
Matt Pocock

Deriving vs Decoupling: When NOT To Be A TypeScript Wizard

In this book teaser, we discuss deriving vs decoupling your types: when building relationships between your types or segregating them makes sense.

Matt Pocock
Matt Pocock

NoInfer: TypeScript 5.4's New Utility Type

Learn how TypeScript's new utility type, NoInfer, can improve inference behavior by controlling where types are inferred in generic functions.

Matt Pocock
Matt Pocock