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
letx: number|null=5;lety=x+5;// no problemletobj: {x: number|null}={x: 5};letz=obj.x+5;// error: 'obj.x' is possibly 'null'. (18047)
π Actual behavior
When nullable object properties have been assigned a non-null value, TS still considers them "possibly null", even though it does not for equivalently typed variables.
π Expected behavior
No error.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
unions narrow, objects with union-typed properties do not; you'd need #42384 for this to work as desired. If you made obj of type {x: number} | {x: null} it would also work today (since that's a union of objects).
π Search Terms
possibly null undefined object property
π Version & Regression Information
Originally detected with 5.7.2, but also confirmed in v5.8.0-dev.20241223 via the playground.
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.8.0-dev.20241223#code/DYUwLgBAHgXBB2BXAtgIxAJwgHwY4wEAvBAKwDcAUKJAJ7HQQDUZV14EA9qgFZwDesPGkw48BAL4NBcUhKo0IALwbceAOijNWEAPS6ImDJwxwA5Gs1mIASwDOEAA6c7dm6mD0zSAmfUAKAEYADgAGABYAdgBKIA
π» Code
π Actual behavior
When nullable object properties have been assigned a non-null value, TS still considers them "possibly null", even though it does not for equivalently typed variables.
π Expected behavior
No error.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: