I have code (see comments):
class ClassA
{
propA: any;
}
class ClassB
{
propB: any;
}
function fn( arr: (ClassA | ClassB)[] )
{
for( let element of arr )
{
if( element instanceof ClassA )
{
element.propA = true; // Work as expected
() =>
{
element.propA; // Unexpected error
}
}
}
}
Message of unexpectedly 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:
class ClassA
{
propA: any;
}
class ClassB
{
propB: any;
}
function fn( element: ClassA | ClassB )
{
if( element instanceof ClassA )
{
element.propA = true; // Work as expected
() =>
{
element.propA; // Work as expected
}
}
}
It's a bug?
Resolved by
aluanhaddad
- contributor TypeScript: