【发布时间】:2016-04-13 19:36:29
【问题描述】:
我是 Typescript 的新手,不知道如何表达这个问题。
我需要访问构造函数中传递的对象的两个“可能”属性。我知道我错过了一些检查以查看它们是否已定义,但 Typescript 向我抛出“'对象'上不存在属性”消息。该消息出现在 selector 和 template 返回。
class View {
public options:Object = {};
constructor(options:Object) {
this.options = options;
}
selector ():string {
return this.options.selector;
}
template ():string {
return this.options.template;
}
render ():void {
}
}
我确信它相当简单,但 Typescript 对我来说是新的。
【问题讨论】:
标签: object typescript