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

时间:2022-09-20 18:36:05

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. Not sure why, but it's been working ever since (yesterday).

感谢大家的帮助。我不确定究竟是什么造成了这种情况,但我重新启动了Visual Studio,一切都恢复正常。不知道为什么,但从那天起(昨天)它一直在工作。


I didn't have these problems last night (with the same code - unchanged):

我昨晚没有遇到这些问题(代码相同 - 没有变化):

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

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;

如果你看不到图片,错误是指这一行:声明var文件;

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.

正如你所看到的,一切看起来都很好。我不明白为什么它会抛出这个错误。

2 个解决方案

#1


11  

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.

我假设您在运行应用程序时遇到此错误,而不是在设计时。

i.e.

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

Should be

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

#2


2  

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.

尝试评论声明行。

#1


11  

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.

我假设您在运行应用程序时遇到此错误,而不是在设计时。

i.e.

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

Should be

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

#2


2  

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.

尝试评论声明行。