Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force TypeScript to recompile all files even if source unchanged?

Tags:

typescript

I've been experimenting with different settings in my tsconfig.json. As part of this, I want to re-compile all my TypeScript files to see how the emitted JavaScript differs with the new settings (e.g. changing the module option).

The underlying .ts files themselves haven't changed, however, and so calling tsc does nothing.

How can I tell tsc to recreate all the files even though it thinks it doesn't need to?

For reference, I'm invoking the TypeScript compiler like so:

node_modules/typescript/bin/tsc --build src/tsconfig.json
like image 993
Sam Avatar asked Aug 06 '19 09:08

Sam


2 Answers

I discovered the answer - although tsc doesn't have a "top-level" force option, since I'm already using the --build option, I can pass --force to that:

node_modules/typescript/bin/tsc --build --force src/tsconfig.json

From the documentation:

There are also some flags specific to tsc -b: [...]

--force: Act as if all projects are out of date

like image 129
Sam Avatar answered Oct 19 '22 15:10

Sam


As a follow to Sam's answer, in the specific case you have the incremental flag set to true (the default) you can also delete the .tsbuildinfo file created by Typescript. This contains metadata about what files are / are not up to date. Without this data, tsc -b will re-compile your entire project.

Incremental flag docs

like image 2
Walter Ennis Avatar answered Oct 19 '22 15:10

Walter Ennis