简体   繁体   中英

How to include and inline external util classes into main TypeScript app?

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM