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
// SetupinterfaceA{value: string;}interfaceB{property: string;}typeAorB=A|B;letisB=(obj: any): obj is B=>{returnobj.hasOwnProperty('property');};// Setup endletoutput=(obj: AorB)=>{if(isB(obj)){console.log(obj.property);// <-- worksletvalues=(newArray(100)).map(a=>obj.property);// <-- Property 'property' does not exist on type 'A | B'console.log(values);}};letsomeObj: B={property: 'value'};output(someObj);
Expected behavior: obj.property within the map should still know its type. This works fine in pre-2.0.
Actual behavior:
The compiler does not recognise property as part of obj within the map.
The text was updated successfully, but these errors were encountered:
This is a dupe of #7719 and so many others. Specifically the comment is here as to why it is the way it is. The team is considering allowing parameters to be declared as const to indicate they will not be changed within a function.
TypeScript Version: typescript@beta (2.0)
Code
Expected behavior:
obj.property
within themap
should still know its type. This works fine in pre-2.0.Actual behavior:
The compiler does not recognise
property
as part ofobj
within themap
.The text was updated successfully, but these errors were encountered: