I'm following a tutorial called THE HERO EDITOR, and it has me creating and editing TypeScript files in an app
folder. The app uses a script tsc -w
, where the w
causes the tsc
transpiler to output a new JavaScript file every time a TypeScript file fails.
This caused me some confusion for several minutes, because when I added a TypeScript class, the editor (Visual Studio Code) underlined the class name and told me it was a duplicate declaration. I saw the JavaScript file with the same name, but no sooner had I deleted it, the duplicate declaration, and thus the JS file, were back.
The script is declared in package.json
:
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
},
Where can I specify where compiled JavaScript goes? I doubt I can do it here, but I can only guess that I need a grunt
or equivalent file, but then what do I do in that file, and do I remove the tsc
entries from `package.js' once another file takes over?
Since the TypeScript compiler preserves the input file path, it will generate x. js in the parent directory of the root directory.
TypeScript compiler uses tsconfig. json to get configuration options for generating JavaScript code from TypeScript source-code. When you uses '$ tsc' command to compile TypeScript code, compiler searches for configurations located in tsconfig. json .
Tsc stands for `TypeScript compiler` and is a simple tool included in Typescript itself, allowing you to compile any ts files into js.
Default: The longest common path of all non-declaration input files. If composite is set, the default is instead the directory containing the tsconfig. json file. When TypeScript compiles files, it keeps the same directory structure in the output directory as exists in the input directory.
We can control where our compiled javascript goes with the help of "outDir
" parameter of "compilerOptions"
in our tsconfig.json
file.
I am also using Visual Studio Code and I generally create my tsconfig.json
file at the project root directory. Here is an example, where I want my compiled javascript to go inside "src/ts-out/"
directory
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true,
"outDir": "src/ts-out/"
}
}
Hope it helps. Happy coding...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With