打字稿不解析文件

TypeScript not resolving file

我知道 TypeScript outFile usage is not recommended.

但我被迫使用它,直到我有时间实施更好的解决方案,例如 AMD。

我相信我有 "module splitting issue"。我在同一目录中有两个文件:

文件referencedFile.ts:

module my.namespace {

   export class one {
   }

   export class two {
   }
}

文件anotherClass.ts:

module my.namespace {
  export class anotherClass {
      constructor() {
         // THROWS ERROR "JavaScript runtime error: Object doesn't support this action"
         var x = new my.namespace.one();
      }
   }
}

在运行时,我在尝试实例化新的 "one" class 时收到错误 "Object doesn't support this action"。在另一个类的构造函数中调试,我可以看到 my.namespace.one 和 my.namespace.two 此时不存在。

我在 anotherClass.ts 的顶部添加了这一行,但没有解决:

/// <reference path="referencedFile.ts" />

我的打字稿 Visual Studio 设置 "Combine Javascript output into one file: Scripts\oneFile.js"

我可以在生成的 "oneFile.js" 中看到,来自 referencedFile.ts 的代码在那里,它在来自 anotherClass.js 的代码之前的文件中,所以我认为不存在是顺序问题。

什么给了?

发件人:// THROWS ERROR "JavaScript runtime error: Object doesn't support this action"

显然顺序是错误的

使用 outFile

指定顺序

您可以使用好的 ol reference 文件技巧。这在此处有详细记录:https://github.com/TypeStrong/grunt-ts#javascript-generation

PS:我相信你知道我对这个问题的看法:https://basarat.gitbooks.io/typescript/content/docs/tips/outFile.html但对于其他人来说仍然值得一提。

尽管我在 VS 2015 中安装了 1.8.36,但最终还是安装了 typescript 1.7.6 问题