Don't get too caught up in the Breeze syntax, but "createEntity" correctly returns a type of breeze.Entity. Why is TypeScript not allowing me to assign that returned object to "instance", which is of type myClass, which implements the breeze.Entity interface?
It seems like this should work, but I get the error "Type 'Entity' is not assignmable to type 'myClass'. Property 'id' is missing in the type 'Entity'.
Am I completely misunderstanding inheritance and/or interfaces in TypeScript (or in general)?
this.instance = EntityManager.createEntity("myClass", myObj); // instance is defined as type 'myType'
If I define this.instance as 'any', everything works, but I lose my strongly typed object elsewhere.
My classes and interfaces...
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;
...
}
I'm not sure if it was other issues, or this, but I got it to work by using "as" described below.
this.instance = EntityManager.createEntity("myClass", myObj) as MyClass;