Closed
Description
In strictNullChecks mode only:
TypeScript Version: nightly (2.0.2)
Code
interface IRoute {
children?: IRoute[];
}
function register(route: IRoute) {
if (route.children) { // <-- route.children is of type IRoute|undefined
Object.keys(route.children).forEach(routeKey => { // <-- route.children is of type IRoute
register(route.children[routeKey]); // <-- Error: Object 'route.children' is possibly 'undefined'.
});
}
}
Expected behavior:
There shouldn't be an error here, because route.children
is being checked 2 lines above.
Actual behavior:
TypeScript fails to recognize route.children
cannot be undefined anymore, because of the nested function. It is the same behavior with both function declaration and arrow functions.