How to delete compiled JS files from previous typescript(.ts) files?

I came here seeing the title, and adding gulp into the mix was not a solution. So here is how I solved it.

Prefix your npm build script with rm -rf ./js/ &&

"scripts": {
    ...
    "build": "rm -rf ./js/ && tsc",
    ...
},

rm -rf ./js/ forcefully removes recursively all files and dirs below ./js/ doku rm in bash

&& says, if successful do the next command && in bash

Title at the time of answering: "How to delete compiled JS files from previous typescript(.ts) files?"


with the latest tsc, you should be fine to do the clean with below command

tsc --build --clean

My current tsc version for your reference

$ tsc --version
Version 3.5.3

Note that --clean flag is part of project-references and works only with it.