将Breeze.Entity分配给TypeScript定义的类
不要过于沉迷于Breeze语法,但是“createEntity”正确地返回了Breeze.Entity的类型。为什么TypeScript不允许我将返回的对象分配给“instance”,它是myClass类型,实现了breeze.Entity接口 这似乎应该可以工作,但我得到错误“类型“Entity”不可分配给类型“myClass”。类型“Entity”中缺少属性“id” 我是否完全误解了TypeScript(或一般)中的继承和/或接口 如果我将this.instance定义为“any”,一切都会正常工作,但我会在其他地方丢失强类型对象 我的类和接口将Breeze.Entity分配给TypeScript定义的类,typescript,breeze,breeze-sharp,Typescript,Breeze,Breeze Sharp,不要过于沉迷于Breeze语法,但是“createEntity”正确地返回了Breeze.Entity的类型。为什么TypeScript不允许我将返回的对象分配给“instance”,它是myClass类型,实现了breeze.Entity接口 这似乎应该可以工作,但我得到错误“类型“Entity”不可分配给类型“myClass”。类型“Entity”中缺少属性“id” 我是否完全误解了TypeScript(或一般)中的继承和/或接口 如果我将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;
...
}
我不确定是其他问题还是这个问题,但我通过使用下面描述的“as”来实现它 this.instance=EntityManager.createEntity(“myClass”,myObj)作为myClass
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;
...
}