-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
Bug Report
Tagged type narrowing doesn't work when one of the tags is a union type. Sorry, not sure how to be more descriptive
🔎 Search Terms
union narrowing
🕗 Version & Regression Information
3.9.7, 4.2.2, Nightly
This is a crashThis changed between versions ______ and _______- This is the behavior in every version I tried, and I reviewed the FAQ for entries about common bugs that aren't bugs
I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
interface A {
type: 'a'
}
interface BC {
type: 'b' | 'c'
}
declare const value: A | BC
let a: A
if (value.type === 'a')
a = value
if (value.type !== 'b' && value.type !== 'c')
// type narrowing doesn't work here, value has type "A | BC" instead of "A"
a = value
declare function isA(x: 'a' | 'b' | 'c'): x is 'a'
if (isA(value.type))
// type narrowing doesn't work with type guard either
a = value
🙁 Actual behavior
Type of a
is not narrowed to A
🙂 Expected behavior
Type of a
is narrowed to A
taras-yurts
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed