Referencing other files inside of a TypeScript Framework
wyeack opened this issue · 4 comments
Hi there - i am trying to use your library to (among other things) compile our TypeScript Framework. Currently, let's say I have the following files:
File1
namespace MBZ { export module HelloWorld { export function Debug(DoSomething) { } } }
File2
namespace MBZ { export module ThisIsSomethingElse { export function Debug(DoSomething) { HelloWorld.Debug("Hello World"); } } }
When I compile this using tsc.exe with no parameters (tsc file1.ts file2.ts), File2 becomes this:
var MBZ; (function (MBZ) { var ThisIsSomethingElse; (function (ThisIsSomethingElse) { function Debug(DoSomething) { MBZ.HelloWorld.Debug("Hello World"); } ThisIsSomethingElse.Debug = Debug; })(ThisIsSomethingElse = MBZ.ThisIsSomethingElse || (MBZ.ThisIsSomethingElse = {})); })(MBZ || (MBZ = {}));
As you can see, HelloWorld.Debug automatically has the full path in front of it. However, when I do the same thing with your transformer (using ChakraCoreJsEngine) I get errors that indicate HelloWorld cannot be found. When I disable errors, I get the following:
var MBZ; (function (MBZ) { var ThisIsSomethingElse; (function (ThisIsSomethingElse) { function Debug(DoSomething) { HelloWorld.Debug("Hello World"); } ThisIsSomethingElse.Debug = Debug; })(ThisIsSomethingElse = MBZ.ThisIsSomethingElse || (MBZ.ThisIsSomethingElse = {})); })(MBZ || (MBZ = {}));
As you can see, HelloWorld does not have the namespace appended. How would I go about fixing this?
Hello, William!
When you compile TypeScript files as follows:
tsc file1.ts file2.ts
Compiler processes files together.
Сompiler from the BundleTransformer.TypeScript module processes each file separately. Accordingly, TypeScript modules are not aware of existence of each other. So you have to give a hint to compiler. In this case, add the triple-slash directive to beginning of the file2.ts
file:
/// <reference path="./file1.ts" />
By the way, this is mentioned in the documentation of module.
So I think part of my confusion here is that normally when I'm using the TypeScript compiler in Visual Studio I have all of my references listed out in my _references.ts file. Is there a way that I can use this with the TypeScript transformer in your library?
Hello, William!
This feature is not supported. In general, usage of _references.ts
and _references.js
files is a feature of Visual Studio.