我决定在我正在开发的某些应用程序中使用 typescript 而不是我不喜欢的javascript,不幸的是我收到了一些奇怪的(至少对我来说)错误。我开发了一些非常小的“应用程序”来检查是否会发生同样的错误。不幸的是它们发生了......
我正在使用 AMD、ecmascript 6 和 Visual Studio 2013。
这是我的根 html 文件:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>TypeScript HTML App</title>
<link rel="stylesheet" href="app.css" type="text/css" />
<script data-main="start" type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.1/require.min.js"></script>
</head>
<body>
<h1>TypeScript HTML App</h1>
<div id="content"></div>
</body>
</html>
我还有一些用 typescript 编写的非常简单的类:
export class trol {
nazwa: string = "trolisko";
echo() {
alert(this.nazwa);
}
}
没有有关任何错误或警告的信息。 VS将其转化为这样的javascript代码:
define(["require", "exports"], function (require, exports) {
"use strict";
class trol {
constructor() {
this.nazwa = "trolisko";
}
echo() {
alert(this.nazwa);
}
}
exports.trol = trol;
});
//# sourceMappingURL=trol.js.ma
但是当我运行“应用程序”时,我收到一些错误:错误消息中的类语句带有下划线,其中写有语法中存在一些错误...
下面我将放置一些屏幕截图:
[![enter image description here][1]][1]
[![enter image description here][2]][2]
[![enter image description here][3]][3]
[![enter image description here][4]][4]
我做错了什么?
最佳答案
What am I doing wrong?
您已将 EcmaScript 版本设置为 EcmaScript 6。请设置为 EcmaScript 5,因为您的目标浏览器不支持它。
PS:这是一本免费的书,可能会对您有更多帮助 https://basarat.gitbooks.io/typescript/content/docs/getting-started.html
关于javascript - 为什么生成的 javascript 代码(基于 typescript )给出错误,即 "class"语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38768044/