Durandal SPA issues with typescript

谁都会走 提交于 2019-12-04 07:13:05

问题


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

"A 'return' statement can only be used within a function body"

I am working on view models. So I need return statement out side of function.

Due to build error I am not able to generate my java-script.

Below is my sample code in Type script:

class typescript1_8{
    constructor(){

    }
}
return new typescript1_8();

Java Script code needs to generate like below:

var typescript1_8 = (function () {
    function typescript1_8() {
    }
    return typescript1_8;
}());
return new typescript1_8();

Note: I need return statement outside of class. It shouldn't throw any error in Type script as mentioned on above.


回答1:


You cannot just return something from empty space, you can use Self-invoking function

(function() {
    return new typescript1_8();
})();


来源:https://stackoverflow.com/questions/35798678/durandal-spa-issues-with-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!