admin管理员组

文章数量:1278985

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 piled 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.

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 piled 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.

Share Improve this question edited Oct 25, 2012 at 2:48 Arrow asked Oct 24, 2012 at 15:17 ArrowArrow 2,9048 gold badges41 silver badges61 bronze badges 9
  • 3 declare in javascript? – Mitch Satchwell Commented Oct 24, 2012 at 15:20
  • 1 See my tags and Question title; it's TypeScript. :-) And yes, declare. 'Cause that's how you do it in TypeScript: typescriptlang: go.microsoft./fwlink/?LinkId=267238 – Arrow Commented Oct 24, 2012 at 15:27
  • I've updated my question to show the resulting JavaScript code from the piled ts file to help you understand. Even the javascript is fine. – Arrow Commented Oct 24, 2012 at 15:28
  • @MitchS - In TypeScript, declare is an Ambient Declaration. – Arrow Commented Oct 24, 2012 at 15:37
  • It seems like a Javascript interpreter is trying to handle the "declare" line (hence the word "Javascript" in the error message) - which it should not because by the time it hits Javascript those lines are removed by TS, correct? Is it possible that VS/TS thinks that your TS is actually JS? Accidental copy/paste? – James Commented Oct 24, 2012 at 15:50
 |  Show 4 more ments

2 Answers 2

Reset to default 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.

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>

You should not need to declare document - it should already be declared. It es from the virtual lib.d.ts file which is referenced by default.

Try menting out the declare line.

本文标签: