- Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Closed
Copy link
Description
// @strictNullChecks: truefunctionf(x: {[key: string]: number;}|null|undefined){for(constkeyinx){// 1console.log(x[key]);// 2}}Expected behavior:
The for..in statement in ECMAScript does not throw if the expression is undefined or null, but rather the loop body is not evaluated. As such, the correct behavior under --strictNullChecks should be:
- The
for..instatement (1) should be legal, even ifxisundefinedornull. - Inside the
for..instatement, thex(2) should no longer be consideredundefinedornull.
Actual behavior:
- The
for..instatement (1) reports the error:Object is possibly 'null' or 'undefined'. - Inside the
for..instatement, thex(2) reports the error:Object is possibly 'null' or 'undefined'.
Jessidhia, aluanhaddad, tabanliviu, soncodi and dantestopp
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript