Skip to content

Control Flow Analysis of aliased conditions on object properties not workingΒ #48929

Closed
@LorenzHenk

Description

@LorenzHenk

Bug Report

πŸ”Ž Search Terms

Control Flow Analysis
type guard

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about type guard and Control Flow Analysis

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface User {
    name: string | null
}

function baz(u: User) {
    const isValid = u.name !== null

    if(isValid) {
        // `u.name` should be `string`, but the following error appears:
        // User.name: string | null
        // Object is possibly 'null'. (2531)
        u.name.length
    }
}

πŸ™ Actual behavior

u.name is of type string | null

πŸ™‚ Expected behavior

u.name should be of type string

Metadata

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