TypeScript is designed for large-scale JavaScripty projects which typically consist of multiple internally produced files along with externally produced libraries. How does the TypeScript compiler (tsc) expect you to provide it with the complete set of files that make up a project?
-
1Can't answer my own question yet, so to get the ball rolling, there are at least two ways in which TSC can become aware of references: 1. Add a triple-slash comment containing a reference element to the top of a .ts source file like this: /// <reference path="node.d.ts" /> 2. Pass the "--reference" option on the command line like this: tsc --reference node.d.ts server.ts – CCoder Oct 02 '12 at 23:22
-
An app that I wrote On the Fly, over at http://onthefly.codeplex.com/ allows you to pass any number of files to the TypeScript compiler - and you can build/compile all of these files at once, with just a click of a button. I'm not "advertising" or "trolling" just letting as many people as possible know there there is a little app that helps ease the pain, since auto compiling with TypeScript has proven to be problematic for many. – Arrow Oct 26 '12 at 10:13
6 Answers
dir *.ts /b /s > ts-files.txt
tsc @ts-files.txt
del ts-files.txt
This will compile all *.ts
files in working directory and its sub directories. If you don't want to include sub directories, just remove the /s
part from the first line.
Note that you can also add other arguments to the tsc
line. Here is what I'm using now for one of my projects:
tsc @ts-files.txt --out ..\output\deerchao.web.js --removeComments

- 10,454
- 9
- 55
- 60
-
I tried this out and I could not get it to work. Any ideas? https://stackoverflow.com/questions/25199866/error-when-compiling-multiple-typescript-files – homaxto Aug 08 '14 at 09:50
-
1Works fine. I run that solution and had the next problem: "error TS5037: Cannot compile external modules unless the '--module' flag is provided." That was easily fixed just adding the module like this: tsc @ts-files.txt --module "commonjs" – Aebsubis Sep 15 '14 at 10:46
-
Nice ! What is the solution for ingnore some subfolders like node_modules ? – Nikola Lukic Oct 10 '22 at 13:37
-
1@NikolaLukic try `dir *.ts /b /s | findstr /V /I "^node_modules$" > ts-files.txt` – deerchao Nov 01 '22 at 00:28
tsc can compile multiple sources in sequence if you just give the names in order:
tsc foo.ts bar.ts
You can also pass a text file containing a list of files and command line arguments from a text file using the @
command line argument.
tsc @compile.txt
and the compile.txt
could look like this:
--module amd
foo.ts
bar.ts
Also note that if on file references another via an import
, tsc
will automatically figure that out without you having to explicitly list the file that it depends on.

- 139,199
- 49
- 202
- 242
-
1When compiling a single file, typescript will output the generated code of other referenced files. By passing all the files to the compiler, it does not do this. (Is there a command line argument to prevent it from including references when compiling a single file?) – Rick Love Oct 11 '12 at 03:35
-
3Actually, it only includes reference code when using the --out parameter. So is there a way to change the output filename without changing the behavior? – Rick Love Oct 11 '12 at 03:40
-
can we get different filename as output file from input after compiling ? if yes then how please suggest any method. i want to convert .ts to .js file. – Pardeep Jain Oct 31 '15 at 06:09
-
Am I the only one who thinks it's strange that I can't run `tsc *.ts` ? – Michel Feb 28 '18 at 16:47
In case anyone needs this for Mac OS X:
find . -name "*.ts" -type f >ts-files.txt
/usr/local/bin/tsc @ts-files.txt --module CommonJS --out ./Deploy/ServerMain.js --removeComments
rm ts-files.txt

- 14,106
- 31
- 105
- 197
With TypeScript 1.5 (beta but the final version should be there soon), you can create a tsconfig.json file to configure the TypeScript compiler and the files to compile (among other things). See my answer over there: How to watch and compile all TypeScript sources?

- 1
- 1

- 1,983
- 2
- 21
- 31
If someone needs multiple files pretranspiled before the actual project compiling, use a separate tsconfig with the --project compiler option.
Compile a project given a valid configuration file. The argument can be a file path to a valid JSON configuration file, or a directory path to a directory containing a tsconfig.json file. See tsconfig.json documentation for more details.
One use case would be the need of the resulting JS files used afterwards in command line arguments for ionic app scripts.

- 8,084
- 3
- 37
- 37
-
it throws `error TS5042: Option 'project' cannot be mixed with source files on a command line.` if you try to use --project or -p option when specifying files to compile. – vikas Jan 26 '18 at 10:45