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

Double (exclusion) inference doesn't narrow union object #61075

Open
exoRift opened this issue Jan 29, 2025 · 4 comments
Open

Double (exclusion) inference doesn't narrow union object #61075

exoRift opened this issue Jan 29, 2025 · 4 comments

Comments

@exoRift
Copy link

exoRift commented Jan 29, 2025

πŸ”Ž Search Terms

"double inference", "exclusion inference", "union object narrow"

πŸ•— Version & Regression Information

I observed this issue on versions

  • 5.4.5
  • 5.7.3

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.3#code/C4TwDgpgBAKhDOwoF4oAoDeBYAUFfUAxgBYSEDWAXFAOQBOCA9gDYBuEAJjbgVMMQEsAdgHNqQgK4BbAEYQ6uAL5QAPlGx4CJMlVrNGAQw7CRNVbXl1GDLjwL8T1CUI4QAZsM5KAlLlyFGIUQoN0ZGajhg1AxlA3hYBGA-HAE3dFDGADptChRkVBp9IxMzFTUM7NJc-ILLa04ab3U7fAqc8haoAHouqAA9AH5OiodRTp7+oZxlCGZ4aA1eNqqOzXwJweGwzNGRcd7N6dwgA

πŸ’» Code

type Test = ({
    check: 'resolved'
    thing: number
} | {
    check: 'loading' | 'errored'
    thing: undefined
})

const foo: Test = {} as Test

if (foo.check === 'loading' || foo.check === 'errored') {
    foo.check
    // ^?
    foo.thing
    // ^?
} else {
    foo.check
    // ^?
    foo.thing
    // ^?

  // `foo.check` is `'resolved'` here, but `foo.thing` is still `number | undefined`
}

πŸ™ Actual behavior

foo.check` is `'resolved'` here, but `foo.thing` is still `number | undefined

This is impossible considering the type

type Test = ({
    check: 'resolved'
    thing: number
} | {
    check: 'loading' | 'errored'
    thing: undefined
})

πŸ™‚ Expected behavior

I expected foo.thing to be of type number since foo.check is of type 'resolved'

Additional information about the issue

No response

@exoRift exoRift changed the title Double inference doesn't narrow union object Double (exclusion) inference doesn't narrow union object Jan 29, 2025
@IllusionMH
Copy link
Contributor

Duplicate of #56023, #31404 etc.

@exoRift
Copy link
Author

exoRift commented Jan 29, 2025

Duplicate of #56023, #31404 etc.

What is the original issue? Is this planned to be fixed?

@MartinJohns
Copy link
Contributor

What is the original issue? Is this planned to be fixed?

He linked the original issue. It's marked as design limitation, so it's unlikely to be solved anytime soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants