TypeScript Version: 2.0.3
Code
All of the code in this issue can be run in the playground.
The following gives this compile error: "Type 'EntityInstance' is not assignable to type 'EntityInstance'."
exportclassEntityInstance{publicdeleted=false;privatechildren=newEntityArray<EntityInstance>();getChildren(): EntityArray<EntityInstance>{returnthis.children;}}exportclassExtendedInstanceextendsEntityInstance{publicanotherProperty=true;getChildren(): EntityArray<ExtendedInstance>{returnsuper.getChildren()asEntityArray<ExtendedInstance>;}}letei=newExtendedInstance();ei.getChildren()[0].anotherProperty=false;exportclassEntityArray<EntityInstance>extendsArray<EntityInstance>{delete(index?: number){letei=newEntityInstance();ei=this.splice(index,1)[0];ei.deleted=true;}}Expected behavior:
This should be allowed. It appears that TS thinks that EntityInstance as specified in "EntityArray" is a different type from EntityInstance. The former EntityInstance doesn't appear to have type information. For example, if I rewrite the delete() as follows there is an error because TS doesn't know about the 'deleted' property:
delete(index?: number){
let ei=this.splice(index,1)[0];ei.deleted=true;}Actual behavior:
TS raises compile error.
More notes:
I could define EntityArray without the <> (which then correctly determines the types in delete) but then I lose type information when I call ExtendedInstance.getChildren(). For example, the above code fails when rewitten as:
exportclassEntityInstance{publicdeleted=false;privatechildren=newEntityArray();getChildren(): EntityArray{returnthis.children;}}exportclassExtendedInstanceextendsEntityInstance{publicanotherProperty=true;getChildren(): EntityArray{returnsuper.getChildren();}}letei=newExtendedInstance();ei.getChildren()[0].anotherProperty=false;exportclassEntityArrayextendsArray<EntityInstance>{delete(index?: number){letei=newEntityInstance();ei=this.splice(index,1)[0];ei.deleted=true;}}I can get by the original error by casting to in the delete method but who wants to do that in Typescript?
delete(index?: number){ let ei=this.splice(index,1)[0]asany;ei.deleted=true;}
TypeScript Version: 2.0.3
Code
All of the code in this issue can be run in the playground.
The following gives this compile error: "Type 'EntityInstance' is not assignable to type 'EntityInstance'."
Expected behavior:
This should be allowed. It appears that TS thinks that EntityInstance as specified in "EntityArray" is a different type from EntityInstance. The former EntityInstance doesn't appear to have type information. For example, if I rewrite the delete() as follows there is an error because TS doesn't know about the 'deleted' property:
Actual behavior:
TS raises compile error.
More notes:
I could define EntityArray without the <> (which then correctly determines the types in delete) but then I lose type information when I call ExtendedInstance.getChildren(). For example, the above code fails when rewitten as:
I can get by the original error by casting to in the delete method but who wants to do that in Typescript?