我正在将多个 TypeScript 文件编译成一个 JavaScript 文件。比如说他们被称为:
A.ts // depends on C.ts
B.ts // depends on C.ts
C.ts
当我检查 JavaScript 输出时,我发现了一个问题:TypeScript 的 __extends
函数由于传递了一个 undefined
值而失败。
编译应按以下顺序进行:
C.ts // because A and B depend on this respectively.
A.ts
B.ts
但不幸的是,它们是根据它们的名称(按字母顺序)而不是依赖顺序编译的。
- 这能解决吗?
- TypeScript 团队是否知道这个问题?
注意:这是一个 Visual Studio TypeScript 编译器问题。大概使用命令行编译器可以解决这个问题,但我想从 Visual Studio 编译。
最佳答案
but unfortunately they were compiled according to their names (alphabetically) rather than in dependency order
https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md
TypeScript 不会进行自动文件排序。您应该使用一些 --module
标志集进行编译,例如commonjs
然后让外部模块加载器为您解析这些依赖链。
更多:http://basarat.gitbooks.io/typescript/content/docs/project/modules.html
关于javascript - TypeScript 编译导致依赖错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31412557/