Using “Watch Mode”

Now, everytime we do a change in the TS file, we do not want to run the compile command. For this we will use the watch mode. This means we can tell TS to watch a file and whenever that file changes TS will recompile.

Do it using:

tsc file-name.ts --watch
				OR
tsc file-name.ts --w

Now, its downside is that we still have to specifically target one file here. Which is not feasible in biger projects.

Compiling the Entire Project / Multiple Files

Suppose you have a project where there are 2 TS files in one you have normal code and in the other you are sending analytics data to the server. Lets emulate this:

analytics.ts:

Screenshot 2022-10-20 at 3.30.03 PM.png

app.ts:

Screenshot 2022-10-20 at 3.32.07 PM.png

index.html

Screenshot 2022-10-20 at 3.30.38 PM.png

Here you can see we are loading 2 files here app.js and analytics.js.

So, we can tell TS that this is an entire project and enter watch mode for all the TS files using:

tsc --init

This will create a tsconfig.json file:

Screenshot 2022-10-20 at 3.33.35 PM.png

This file is the indicator for TS that any project where this file is should be managed by TS.