Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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):

enter image description here

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.

like image 321
Arrow Avatar asked Oct 24 '12 15:10

Arrow


2 Answers

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.

i.e.

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

Should be

<script src="app.js"></script>
like image 155
Fenton Avatar answered Oct 31 '22 16:10

Fenton


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.

like image 22
Quango Avatar answered Oct 31 '22 14:10

Quango