没有 /// <reference> 标签,TypeScript 的 "Combine JavaScript output into file" 选项无法推断出正确的脚本顺序
TypeScript's "Combine JavaScript output into file" option doesn't infer correct script order without /// <reference> tags
我正在开发一个使用 "Combine JavaScript output into file" 选项的 TypeScript 解决方案:
我会经常引用另一个文件中定义的项目,例如:
在MyBaseClass.ts
中:
export class MyBaseClass { }
在MySubClass.ts
中:
export class MySubClass extends MyBaseClass { }
在开发过程中,Visual Studio 可以理解 MySubClass
引用了 MyBaseClass.ts
中定义的 MyBaseClass
- 解决方案成功构建,我可以导航到 MyBaseClass
使用 F12.
但是,我运行进入运行时出现错误,我运行的解决方法是因为生成的JavaScript文件在[=18=之前定义了MySubClass
].
我可以通过在 MySubClass.ts
中添加 /// <reference>
标签来修复这些 运行 时间错误:
/// <reference path="MyBaseClass.ts" />
export class MySubClass extends MyBaseClass { }
为什么 IDE 理解 MySubClass
和 MyBaseClass
之间的关系,但编译器没有正确排序这些 [=55= 的定义]es 在生成的输出中?
我希望生成的输出能够正确推断 class 定义的顺序(首选),或者如果 /// <reference>
标签不存在,TypeScript 编译器会抛出错误。
Why does the IDE understand the relationship between MySubClass and MyBaseClass,
只知道语义关系。不是运行时要求。如何加载模块 取决于您。
注:https://github.com/TypeStrong/grunt-ts#reference and https://github.com/TypeStrong/grunt-ts#javascript-generation
我真希望这个问题能得到解决。 Typescript intellisense 在推断正确顺序时似乎没有任何问题。当具有选项 "Combine into one file" 的编译器没有解决这个问题时,它会预先呈现较大的 js 文件不可靠......
对这个问题的正常反应是,使用动态加载……是的。但就我而言,动态加载的模块已经存在许多类,它们在编译成单个文件的单独项目中。因此,该问题也存在于该场景中......
看起来现在可以使用 TypeScript 1.8:
https://medium.com/@vivainio/with-latest-typescript-you-may-not-need-webpack-417d2ef0e773#.tcu41xsft
您需要确保选择了系统或 AMD 模块系统:
我正在开发一个使用 "Combine JavaScript output into file" 选项的 TypeScript 解决方案:
我会经常引用另一个文件中定义的项目,例如:
在MyBaseClass.ts
中:
export class MyBaseClass { }
在MySubClass.ts
中:
export class MySubClass extends MyBaseClass { }
在开发过程中,Visual Studio 可以理解 MySubClass
引用了 MyBaseClass.ts
中定义的 MyBaseClass
- 解决方案成功构建,我可以导航到 MyBaseClass
使用 F12.
但是,我运行进入运行时出现错误,我运行的解决方法是因为生成的JavaScript文件在[=18=之前定义了MySubClass
].
我可以通过在 MySubClass.ts
中添加 /// <reference>
标签来修复这些 运行 时间错误:
/// <reference path="MyBaseClass.ts" />
export class MySubClass extends MyBaseClass { }
为什么 IDE 理解 MySubClass
和 MyBaseClass
之间的关系,但编译器没有正确排序这些 [=55= 的定义]es 在生成的输出中?
我希望生成的输出能够正确推断 class 定义的顺序(首选),或者如果 /// <reference>
标签不存在,TypeScript 编译器会抛出错误。
Why does the IDE understand the relationship between MySubClass and MyBaseClass,
只知道语义关系。不是运行时要求。如何加载模块 取决于您。
注:https://github.com/TypeStrong/grunt-ts#reference and https://github.com/TypeStrong/grunt-ts#javascript-generation
我真希望这个问题能得到解决。 Typescript intellisense 在推断正确顺序时似乎没有任何问题。当具有选项 "Combine into one file" 的编译器没有解决这个问题时,它会预先呈现较大的 js 文件不可靠...... 对这个问题的正常反应是,使用动态加载……是的。但就我而言,动态加载的模块已经存在许多类,它们在编译成单个文件的单独项目中。因此,该问题也存在于该场景中......
看起来现在可以使用 TypeScript 1.8:
https://medium.com/@vivainio/with-latest-typescript-you-may-not-need-webpack-417d2ef0e773#.tcu41xsft
您需要确保选择了系统或 AMD 模块系统: