Is it possible to compile a single TypeScript file to an output path using the tsc command?

13,648

When you use the --out parameter, you get a single file with the compiler walking the dependencies and working out the correct order for the final file.

For example...

tsc --out final.js app.ts

Will find any dependencies in app.ts and compile them all too. After it works out the correct order it will save all of the JavaScript in final.js. If this JavaScript file is empty, it is normally indicative of a compiler error.

It is not possible to use the --out parameter to generate a JavaScript file for just the TypeScript file you specify, unless that file has no dependencies.

Share:
13,648

Related videos on Youtube

cnp
Author by

cnp

Updated on June 04, 2022

Comments

  • cnp
    cnp almost 2 years

    In an attempt to separate my .ts source files from the .js output, I'm trying to implement a formal file-watcher in TypeScript and it seems as though the ability to specify an output path for a single file does not exist.

    The flow, just to be clear: I begin watching my entire src directory, make a change to, say, src/views/HomeView.ts, and i want node to pick up that the file has been changed, and move the compiled version to public/js/views/HomeView.js.

    Using tsc myfile.ts --out myfile.js it travels through all of the modules and compiles each in the same path that the .ts file exists, without placing the final file(s) in the properly specified path. It does however create an empty file where I would like it to end up.

    I'm wondering:

    1) Is it possible to use the --out parameter and only compile that one file? I do not want it to traverse imports and compile every single file, but merely do syntax / error checking at compile-time (and that's only a secondary requirement, not necessary); and

    2) Is there a bug in the compiler that prevents it from properly combining / creating files? Again, the final output in the --out path directive is empty, but a file is indeed created.

    Any help would be appreciated.

    * Update *

    While I don't want to close this question as I do believe it's still an issue, I went ahead and implemented the core TypeScript compiler to achieve what I needed to do, bypassing tsc altogether. Please see https://github.com/damassi/TypeScript-Watcher for more information and usage.