Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
LorenzHenk opened this issue May 3, 2022 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@LorenzHenk
Copy link

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

@MartinJohns
Copy link
Contributor

This is working as intended. See #48891.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label May 3, 2022
@LorenzHenk
Copy link
Author

Ahh I see, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants