简体   繁体   English

我做错了什么,或者这是一个错误? (TypeScript / Visual Studio 2012)

[英]Have I done something wrong, or is this a bug? (TypeScript/Visual Studio 2012)

Resolved: 解决:

Thank you all for your help. 感谢大家的帮助。 I'm not sure exactly what caused this, but I restarted Visual Studio and everything went back to normal. 我不确定究竟是什么造成了这种情况,但我重新启动了Visual Studio,一切都恢复正常。 Not sure why, but it's been working ever since (yesterday). 不知道为什么,但从那天起(昨天)它一直在运作。


I didn't have these problems last night (with the same code - unchanged): 我昨晚没有遇到这些问题(代码相同 - 没有变化):

在此输入图像描述

I don't see what the issue is. 我不明白这是什么问题。

The error I am getting is: 我得到的错误是:

JavaScript critical error at line 1, column 9 in [path/app.ts] SCRIPT1004: Expected ';'. 第1行第9行中的JavaScript严重错误[path / app.ts] SCRIPT1004:预期';'。

What the deuce?! 什么是平分?!

Incase you can't see the image, the error is referring to this line: declare var document; 如果你看不到图片,错误是指这一行: declare var document;

Update 更新

The javascript file which is a result of the TypeScript being compiled into JavaScript looks like this: 将TypeScript编译成JavaScript的结果的javascript文件如下所示:

window.onload = function () {
    start();
};
function sayHello(msg) {
    return msg = "Hello, therel ol!";
}
function start() {
    var element = document.getElementById("link");
    element.addEventListener("click", function () {
        var element = document.getElementById("response").innerText = sayHello("Hi");
    }, false);
    if(XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
}

And as you can see, everything looks fine. 正如你所看到的,一切看起来都很好。 I don't get why it's throwing this error. 我不明白为什么它会抛出这个错误。

My guess is that you have referenced the app.ts file on your page by mistake, when you should have referenced the app.js file. 我的猜测是,当你应该引用app.js文件时,你错误地引用了页面上的app.ts文件。

I'm assuming you get this error when running your application, not at design time. 我假设您在运行应用程序时遇到此错误,而不是在设计时。

ie

<script src="app.ts"></script>

Should be 应该

<script src="app.js"></script>

You should not need to declare document - it should already be declared. 您不应该声明文档 - 它应该已经声明。 It comes from the virtual lib.d.ts file which is referenced by default. 它来自默认引用的虚拟lib.d.ts文件。

Try commenting out the declare line. 尝试评论声明行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM