Skip to content
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

true || leads to "Object possibly 'undefined'" #35238

Closed
yonilerner opened this issue Nov 20, 2019 · 3 comments
Closed

true || leads to "Object possibly 'undefined'" #35238

yonilerner opened this issue Nov 20, 2019 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@yonilerner
Copy link

TypeScript Version: Nightly (as of date of issue creation)

Search Terms:

  • "Object is possibly undefined" (and variations)
  • "true ||"

Code

interface Foo {
    bar?: boolean
}
function test(x: Foo | undefined) {
    if (!x?.bar) {
        return
    }
    return true || x.bar
}

Expected behavior:
Compiles with no errors

Actual behavior:
"Object is 'undefined'" on x in the statement return true || x.bar
This is especially weird because if you remove the true || so you just have return x.bar, there is no error, and if you move the extra condition to the end so you have return x.bar || true there is also no error.

Playground Link: http://www.typescriptlang.org/play/index.html?ts=Nightly#code/JYOwLgpgTgZghgYwgAgGIHt3IN4FgBQyRyARnFAPwBcpmANhHCAQL4EwCuICYw6IySAGcwACgAeNDFgA+yLgBMIMUBAUBKHAWLJgMZKICE4igDoyUTXkI7iUCGA5RmNom1fJ7j54KgcUMnLi5uSsQA

@jack-williams
Copy link
Collaborator

I think this is duplicate of #26914.

@yonilerner
Copy link
Author

Makes sense. Should I close this or wait for someone else to mark it duplicate?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 20, 2019
@RyanCavanaugh
Copy link
Member

Always OK to self-close here. Thanks for asking!

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