2

I'm using the new TypeScript for VS tooling system to generate JavaScript programs from TypeScript syntax. I need to define my app and the utils in seperate files, and I need to know how the util "classes" and functions will be included into the main app.

  1. I've heard of the /// <reference path="....ts" /> syntax that lets you access code from external files. Does this syntax act like include would in C++? Would it pull the used classes/functions into the main app.ts file or would it simply expect the target files to exist as .js files in the same directory?

  2. Should I use internal modules to define classes that will be included (inlined) into the main app?

Community
  • 1
  • 1
Robin Rodricks
  • 110,798
  • 141
  • 398
  • 607

1 Answers1

5

If you have a /// <reference ... > tag to an other .ts file, those referenced files (recursively) will be compiled into the same .js file if you specify a filename to the --out switch. Otherwise, that same set of files will be side-by-side compiled (a.ts -> a.js).

None of this behavior is dependent on using internal modules vs keeping things at top-level. If you choose to use external modules, though, the story is very different (see existing material on this, probably).

Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235
  • I'm getting the error : "Cannot compile dynamic modules when emitting into single file" .. because I'm using NodeJS dynamic modules. Can I keep the NodeJS modules dynamic and yet allow my class files to be folded into the final file? – Robin Rodricks Apr 07 '13 at 17:58
  • 1
    Not in 0.8.3. You might be able to do this when 0.9 comes out (or possibly post-0.9) – Ryan Cavanaugh Apr 07 '13 at 18:48
  • 3
    Is there any other way to simply include external files inline? Like `#include` in C++? – Robin Rodricks Apr 07 '13 at 19:55