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
2 Answers
Reset to default 11My 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.
本文标签:
版权声明:本文标题:javascript - Have I done something wrong, or is this a bug? (TypeScriptVisual Studio 2012) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741280992a2370005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论