Skip to content

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

Closed as not planned

Description

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

Activity

  1. changed the title [-]Double inference doesn't narrow union object[/-] [+]Double (exclusion) inference doesn't narrow union object[/+] on Jan 29, 2025
  2. IllusionMH commented on Jan 29, 2025

    @IllusionMH
    Contributor

    Duplicate of #56023, #31404 etc.

  3. exoRift commented on Jan 29, 2025

    @exoRift
    Author

    Duplicate of #56023, #31404 etc.

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

  4. MartinJohns commented on Jan 31, 2025

    @MartinJohns
    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.

  5. typescript-bot commented on Feb 10, 2025

    @typescript-bot
    Contributor

    This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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