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
abstractclassChildBase{id: string;}classChildAextendsChildBase{foo: string;}classParentA{children: ChildA[];}classChildBextendsChildBase{bar: string;}classParentB{children: ChildB[];}functionfindChild(parent: ParentA|ParentB,id: string){returnparent.children.findIndex(_=>_.id===id);// Compile error here}// Note that the following works (but it changes the meaning of the array)functionfindChild2(parent: ParentA|ParentB,id: string){return(<(ChildA|ChildB)[]>parent.children).findIndex(_=>_.id===id);}
Expected behavior:
Compiles without error
Actual behavior:
Compiles with error:
Cannot invoke an expression whose type lacks a call signature. Type '((predicate: (value: ChildA, index: number, obj: ChildA[]) => boolean, thisArg?: any) => number) ...' has no compatible call signatures.
The text was updated successfully, but these errors were encountered:
@aluanhaddad thanks for you reply and appreciate those workarounds. I posted above because I feel that there is a bug here. Also this issue exists without any inheritance, which makes both of your workaround less appealing.
TypeScript Version: 2.1.4
Code
Expected behavior:
Compiles without error
Actual behavior:
Compiles with error:
The text was updated successfully, but these errors were encountered: