You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceHuman{age?: number;}functionconsume(obj: Human){obj.age=undefined;}constobj: Human={age: 42};if(obj.age){consume(obj);constage: number=obj.age;// Not an error}
π Actual behavior
Assignment of const age: number succeeds with undefined.
π Expected behavior
obj.age is assessed as number | undefined, causing the assignment to fail.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
π Search Terms
control flow analysis, branch, condition
π Version & Regression Information
Tested in 5.8.2.
β― Playground Link
https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true#code/JYOwLgpgTgZghgYwgAgBIFcC2cTIN4BQyycA5hAPwBcyIWARtANwEC+BBM6ICYwA9rgSCAzlggAKfvQBWNDNhABKfEWTSZAOjIoAvMm4ATCDFARDLdgWEgRYdbPlYcyfXhLkaAFgBMyVizAMMhSstrkKoTENmKYkhpKLNGi9jo0dJiMUK4OWjpMyAD0hcgAcvypuNBQ-FBsBEA
π» Code
π Actual behavior
Assignment of
const age: number
succeeds withundefined
.π Expected behavior
obj.age
is assessed asnumber | undefined
, causing the assignment to fail.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: