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
classClassA{propA: any;}classClassB{propB: any;}functionfn(arr: Array<ClassA|ClassB>){for(letelementofarr){if(elementinstanceofClassA){element.propA=true;// Work as expected()=>{element.propA;// Unexpected error}}}}
Expected behavior:
Works without error
Actual behavior:
Throw error:
Property 'propA' does not exist on type 'ClassA | ClassB'.
Property 'propA' does not exist on type 'ClassB'.
When I remove the loop for(){}. Works as expected:
classClassA{propA: any;}classClassB{propB: any;}functionfn(element: ClassA|ClassB){if(elementinstanceofClassA){element.propA=true;// Work as expected()=>{element.propA;// Work as expected}}}