-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
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.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug