2016-08-16 49 views
0

我知道TypeScript outFile usage is not recommendedTypeScript未解析文件

但是我不得不使用它,直到我有时间实施更好的解决方案,比如AMD。

我相信我有一个“模块分裂问题”。我在同一个目录的两个文件:

文件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(); 
     } 
    } 
} 

在运行时,我得到错误“对象不支持这个动作“当试图实例化一个新的”一个“类。在另一个类的构造函数中进行调试时,我可以看到my.namespace.one和my.namespace.two在此处不存在。

我说这条线在anotherClass.ts的顶部,它并没有解决:

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

我的打字稿的Visual Studio设置“合并这些JavaScript输出到一个文件:脚本\ oneFile.js”

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

什么给?

+1

您正在使用什么版本的TypeScript? –

+0

1.8.36在VS 2015中列出,但我在程序文件中安装了1.7.6工具。我删除了1.7.6工具,这可能已经解决。将验证,但想明白为什么 – user210757

+1

因为您正在使用,您可能想开始查看['import'关键字](https://www.typescriptlang.org/docs/handbook/module-resolution.html)一个支持它的版本。它接管了'///

回答

0

这个问题最终被安装了打字稿1.7.6,尽管我已经安装了VS 2015 1.8.36

1

来源:// THROWS ERROR "JavaScript runtime error: Object doesn't support this action"

显然顺序是错误的

指定与outFile

排序您可以使用好醇reference文件伎俩。这是记录在这里:https://github.com/TypeStrong/grunt-ts#javascript-generation

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

+0

了不起的信息。尽管我在VS 2015中安装了1.8.36,但问题最终仍然是安装了打字稿1.7.6。 - 我在我的问题中包含了该链接 – user210757