简体   繁体   中英

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. 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 ';'.

What the deuce?!

Incase you can't see the image, the error is referring to this line: declare var document;

Update

The javascript file which is a result of the TypeScript being compiled into JavaScript looks like this:

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.

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.

Try commenting out the declare line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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