Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I speed up initial TypeScript compile times

I have a fairly big TypeScript project (200+ files) and it takes some time (10s+) to boot up when I run it in watch mode (tsc --watch). However once its going it is pretty fast to do a full typecheck TypeScript.

How can I speed up the initial boot of tsc --watch?

like image 775
basarat Avatar asked Mar 18 '19 00:03

basarat


People also ask

Does TypeScript compile time?

Yes. In fact, other than a very small aspect related to enum s, TypeScript doesn't exist at runtime at all. TypeScript compiles to JavaScript, which is a dynamically-typed language.

Does TypeScript run faster?

JavaScript though it is very popular and is the slowest language that takes a lot of time to the execution the commands. Instead, the Typescript is much faster and more efficient as compared to JavaScript both in terms of speed of execution and the scaling of devices as well.

Does TypeScript slow down?

Does TypeScript slow down? Yes, it slows you down because you need to think about your domain and how that maps into types (whether you think those types exist or not, they do).


1 Answers

TypeScript 3.4 rc got the --incremental compiler option (blog post).

When it is enabled TypeScript will generate a .tsbuildinfo file if there isn't one already (so you still play the 10s+ penalty once). But if it exists, a cold tsc --watch run will be super fast (no longer 10s delay).

How to enable incremental builds

Either with command line flag --incremental or in your tsconfig.json:

{
    "compilerOptions": {
        "incremental": true
    }
}
like image 152
basarat Avatar answered Sep 24 '22 05:09

basarat