Typescript 0.9 列出了其中一项重大更改:
'module' 关键字不再创建类型
描述:在 0.9.0 中,对命名空间、类型和值的角色进行了更清晰的区分。模块现在只对命名空间和值有贡献,不再贡献类型。原因:模块角色的这种简化允许模块现在更容易地扩展类和函数。
然而,当我编译模块示例时:
module Sayings {
export class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
}
var greeter = new Sayings.Greeter("world");
var button = document.createElement('button');
button.innerText = "Say Hello";
button.onclick = function() {
alert(greeter.greet());
};
document.body.appendChild(button);
0.9.0 和 0.8.3 产生完全相同的输出(除了一些空格):
var Sayings;
(function (Sayings) {
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
Sayings.Greeter = Greeter;
})(Sayings || (Sayings = {}));
var greeter = new Sayings.Greeter("world");
var button = document.createElement('button');
button.innerText = "Say Hello";
button.onclick = function () {
alert(greeter.greet());
};
document.body.appendChild(button);
那么突破性的变化在哪里呢?