问题描述
我使用TypeScript 1.8将我的Durandal SPA应用程序从VS_2012更新为VS_2015,它将生成JavaScript(ECMA5).我解决了所有构建错误.但是我无法修复一个叫做
I am updated my durandal SPA application from VS_2012 to VS_2015 with TypeScript 1.8 which will generate JavaScript (ECMA5). I resolved all build errors.But I am unable to fix one typescript error called
'return'语句只能在函数体内使用"
我正在研究视图模型.因此,我需要在函数之外使用return语句.
I am working on view models. So I need return statement out side of function.
由于构建错误,我无法生成我的Java脚本.
Due to build error I am not able to generate my java-script.
下面是我在Type脚本中的示例代码:
class typescript1_8{
constructor(){
}
}
return new typescript1_8();
Java脚本代码需要如下生成:
var typescript1_8 = (function () {
function typescript1_8() {
}
return typescript1_8;
}());
return new typescript1_8();
注意:我需要在课堂以外的回程声明.如上所述,它不应在Type脚本中引发任何错误.
Note: I need return statement outside of class. It shouldn't throw any error in Type script as mentioned on above.
推荐答案
您不能只从空白处返回内容,而是可以使用Self-invoking
函数
You cannot just return something from empty space, you can use Self-invoking
function
(function() {
return new typescript1_8();
})();
这篇关于Durandal SPA与打字稿有关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!