TypeScript 导出可以重载吗?
Can TypeScript exports be overloaded?
我在查看 flux 时发现了一些奇怪的打字稿语法,这没有任何意义。例如;
class Action {
private _source: Action.Source
constructor( source: Action.Source ) {
this._source = source
}
get source() {
return this._source
}
}
module Action {
export enum Source {
View,
Server
}
}
export = Action
export = Action 在这里到底做了什么?导出模块和 class 是否超载?以某种方式混合它们?我不理解这里的语义..
它正在使用声明合并。幕后发生的事情本质上是这样的:
// class is defined
function Action(source) {
this._source = source;
}
Object.defineProperty(Action.prototype, "source", {
get: function () {
return this._source;
},
enumerable: true,
configurable: true
});
// enum is defined on the Source property of Action—NOT on Action's prototype
Action.Source = ...enum object definition...
export = Action;
阅读 Handbook 中有关 "Merging Modules with Classes, Functions, and Enums" 的更多信息。
我在查看 flux 时发现了一些奇怪的打字稿语法,这没有任何意义。例如;
class Action {
private _source: Action.Source
constructor( source: Action.Source ) {
this._source = source
}
get source() {
return this._source
}
}
module Action {
export enum Source {
View,
Server
}
}
export = Action
export = Action 在这里到底做了什么?导出模块和 class 是否超载?以某种方式混合它们?我不理解这里的语义..
它正在使用声明合并。幕后发生的事情本质上是这样的:
// class is defined
function Action(source) {
this._source = source;
}
Object.defineProperty(Action.prototype, "source", {
get: function () {
return this._source;
},
enumerable: true,
configurable: true
});
// enum is defined on the Source property of Action—NOT on Action's prototype
Action.Source = ...enum object definition...
export = Action;
阅读 Handbook 中有关 "Merging Modules with Classes, Functions, and Enums" 的更多信息。