-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed as not planned
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
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
π» 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
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created