TypeScript Version:
typescript@1.9.0-dev.20160521-1.0
Code
function foo(ids: any[], bars: { id: any }[], searchId: any) {
const foundBar = bars.find(bar => bar.id === searchId);
if (foundBar) {
const id = ids.find(id => id === foundBar.id);
// ^^^^^^^^ TS2532: Object is possibly 'undefined'.
}
}
Expected behavior:
Should not given an error because foundBar cannot be undefined because of if (foundBar) check
Actual behavior:
error: TS2532: Object is possibly 'undefined'.