Typescript - can tsc work with the whole folder?

I am very surprised that this is not in the documents that I could find, but is there a way to just tell tsc to run with all the files in the directory and its children without going through the whole tsconfig.json installation?

+20
typescript
source share
5 answers

Not what I know from. Using tsc from the command line without tsconfig.json requires you to specify each file separately, for example like this:

 tsc MyFile1.ts MyFile2.ts MyFile3.ts 

However, it looks like you can just create an empty tsconfig.json (that is, just {} ) in the root of your TypeScript directory, and it will do what you want. From https://github.com/Microsoft/TypeScript/wiki/tsconfig.json :

If the "files" property is not present in tsconfig.json , the compiler by default includes all TypeScript files (* .ts or * .tsx) in the directory and subdirectories.

+13
source share

You can use globs

 tsc x/file1.ts x/file2.ts x/file3.ts 

should be equivalent

 tsc x/*.ts 
+4
source share

If you have a tsconfig.json file inside your project folder, you can directly print

tsc this command will compile all your ts files in the current folder, if you don’t have a tsconfig.json file, you can generate it by typing: '

tsc -init

0
source share

This may be redundant, but I just wrote a PS function for use in VS Code as a task;

 function CompileTypeScriptFiles($folder) { $tsFiles = Get-ChildItem $folder -Filter "*ts" -Recurse $tsFiles | ForEach-Object { $tsFile = $_.FullName; $options = $tsFile + " --outDir js --sourceMap" Start-Process "tsc" $options } } 
0
source share

Windows users should use a for loop:

 for %f in (./path/*.ts) do npx tsc "./path/%f" --lib es2018 --outDir ./path/bin 

Remember to double % if you use it inside the bat file:

 for %%f in (./path/*.ts) do npx tsc "./path/%%f" --lib es2018 --outDir ./path/bin 
0
source share

All Articles