Durandal SPA与打字稿有关的问题 [英] Durandal SPA issues with typescript

查看:82
本文介绍了Durandal SPA与打字稿有关的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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与打字稿有关的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆