Closed
Description
TypeScript Version: typescript@beta (2.0)
Code
// Setup
interface A {
value: string;
}
interface B {
property: string;
}
type AorB = A | B;
let isB = (obj: any): obj is B => {
return obj.hasOwnProperty('property');
};
// Setup end
let output = (obj: AorB) => {
if (isB(obj)) {
console.log(obj.property); // <-- works
let values = (new Array(100)).map(a => obj.property); // <-- Property 'property' does not exist on type 'A | B'
console.log(values);
}
};
let someObj: 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
.