Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incremental compilation with TypeScript while using --noEmit?

Tags:

typescript

I would like to use TypeScript's --incremental mode to make it faster on repeated runs. However my tsconfig.json sets "noEmit": true because I'm currently only using TypeScript for type checking and not code generation.

If I run tsc --incremental --outDir ~/tmp/typescript --noEmit it doesn't appear to output a tsconfig.tsbuildinfo file and therefore doesn't actually incrementally compile on repeated runs.

I suppose I could actually enable emit and run tsc --incremental --outDir ~/tmp/typescript --noEmit false but then it generates not just tsconfig.tsbuildinfo but also a bunch of JS files I don't need, which isn't ideal.

Is there a way I can run tsc --incremental --noEmit, actually incrementally compile, and only generate the tsconfig.tsbuildinfo file needed for incremental compilation?

like image 202
David Foster Avatar asked Jul 17 '19 15:07

David Foster


People also ask

What is incremental compilation TypeScript?

TypeScript 3.4 introduces a new flag called incremental which tells TypeScript to save information about the project graph from the last compilation. The next time TypeScript is invoked with incremental , it will use that information to detect the least costly way to type-check and emit changes to your project.

Does TypeScript require compilation?

The TypeScript compiler compiles these files and outputs the JavaScript with . js extension by keeping the same file name as the individual input file. The TypeScript compiler also preserves the original file path, hence the . js output file will be generated where the input file was in the directory structure.

Does TSC use Tsconfig?

Running tsc locally will compile the closest project defined by a tsconfig. json , you can compile a set of TypeScript files by passing in a glob of files you want.

What is TSC in TypeScript?

The TypeScript Compiler (also known as "tsc") is the backbone of many bundlers, plugins, and tools that work with TypeScript. While we don't often invoke tsc directly, we do configure how tsc behaves inside of the bundlers that we use.


1 Answers

Update: The combination of incremental and noEmit is finally possible with TS 4.0.


Up to now, unfortunately there is no way to have incremental builds with noEmit option enabled for faster type checking runs. E.g. this would be useful, when there is a separate typescript compile step with @babel/preset-typescript or similar.

Developer's statement regarding your question:

The problem here is that incremental is on by default if composite is on, so this is an actual risky change because it's going to mean new build artifacts in unexpected places for people using --noEmit today.

If the build info file path is specified manually, then writing it out does seem OK

So hopefully there is a chance, that such a feature will be implemented in future releases. You may follow here for progress tracking.

like image 52
ford04 Avatar answered Oct 05 '22 03:10

ford04