我正在开发一个使用“将 JavaScript 输出合并到文件中”选项的 TypeScript 解决方案:
我经常引用另一个文件中定义的项目,例如:
In MyBaseClass.ts
:
export class MyBaseClass { }
In MySubClass.ts
:
export class MySubClass extends MyBaseClass { }
While developing, Visual Studio has no problem understanding that MySubClass
references the MyBaseClass
defined in MyBaseClass.ts
- the solution successfully builds and I can navigate to MyBaseClass
using F12.
但是,当我运行该解决方案时,我遇到了运行时错误,因为生成的 JavaScript 文件定义了MySubClass
before MyBaseClass
.
我可以通过添加来修复这些运行时错误/// <reference>
tag in MySubClass.ts
:
/// <reference path="MyBaseClass.ts" />
export class MySubClass extends MyBaseClass { }
为什么IDE能够理解之间的关系MySubClass
and MyBaseClass
,但是编译器在生成的输出中没有正确排序这些类的定义?
我要么希望生成的输出能够正确推断类定义的顺序(首选),要么希望 TypeScript 编译器在以下情况下抛出错误:/// <reference>
标签不存在。
为什么IDE理解MySubClass和MyBaseClass之间的关系,
它只知道语义关系。不是运行时要求。你如何进行模块加载是由你决定.
Note: https://github.com/TypeStrong/grunt-ts#reference https://github.com/TypeStrong/grunt-ts#reference and https://github.com/TypeStrong/grunt-ts#javascript- Generation https://github.com/TypeStrong/grunt-ts#javascript-generation
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)