Skip to content

strictNullChecks false positives for non-null object propertiesΒ #60847

Closed as not planned
@runny-yolk

Description

πŸ”Ž 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

let x: number | null = 5;
let y = x + 5; // no problem

let obj: {x: number | null} = {x: 5};
let z = 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions