You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceCategory{id: string;description: string;}interfaceTreeNodeBase{readonlychildren: TreeNode[];title() : string;id(): string;}interfaceCategoryTreeNodeextendsTreeNodeBase{readonlykind: "category";readonlyitem: Category;}interfaceEmptyTreeNodeextendsTreeNodeBase{readonlykind: "empty";}typeTreeNode=EmptyTreeNode|CategoryTreeNode;// More variants in actual case.functioncreateCategoryNode(category : Category,children : TreeNode[]) : CategoryTreeNode{return{kind: "category",item: category,children: children,title(){return(<Category>this.item).description;},// Why is type of this.item not inferred ?id(){return(<Category>this.item).id;}// Why is type of this.item not inferred ?};}
Expected behavior:
The factory method createCategoryNode should be able to return an object that is a CategoryTreeNode in a type safe manner without having to specify the type as done above when implementing the title and id functions.
Actual behavior:
Right now, unless the type of this.item is explicitly given, typescript will regard the type of item as any instead of Category. Thus, the type of this.item is not inferred correctly.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.0.0
Expected behavior:
The factory method createCategoryNode should be able to return an object that is a CategoryTreeNode in a type safe manner without having to specify the type as done above when implementing the title and id functions.
Actual behavior:
Right now, unless the type of this.item is explicitly given, typescript will regard the type of item as any instead of Category. Thus, the type of this.item is not inferred correctly.
The text was updated successfully, but these errors were encountered: