【发布时间】:2017-07-21 07:03:51
【问题描述】:
不要太沉迷于 Breeze 语法,但“createEntity”正确地返回了一种类型的轻风.Entity。为什么 TypeScript 不允许我将返回的对象分配给 myClass 类型的“实例”,它实现了轻量级实体接口?
这似乎应该可行,但我收到错误“类型'Entity'不可分配给类型'myClass'。类型'Entity'中缺少属性'id'。
我是否完全误解了 TypeScript(或一般而言)中的继承和/或接口?
this.instance = EntityManager.createEntity("myClass", myObj); // instance is defined as type 'myType'
如果我将 this.instance 定义为“any”,一切正常,但我在其他地方丢失了强类型对象。
我的类和接口...
export class myClass extends base implements Interfaces.IMyClass, breeze.Entity {
public id: number;
....
constructor() {
super();
}
}
export class base implements breeze.Entity {
constructor() { }
public entityAspect: breeze.EntityAspect;
public entityType: breeze.EntityType;
}
export interface IMyClass extends breeze.Entity {
id: number;
...
}
【问题讨论】:
标签: typescript breeze breeze-sharp