- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.1k
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
π Search Terms
type guard conditional type
π Version & Regression Information
- This changed between versions 4.2.3 and 4.3.2
β― Playground Link
Playground link with relevant code
π» Code
interface A<S> {
    a: S
}
interface B<S> {
    b: S
}
interface C<S> {
    c: S
}
type U1<S> = A<S> | B<S> | C<S>
function f1<S>(u: U1<S>): u is B<S> | C<S> {
    return false
}
function test1<S>(x: U1<S>) {
    if (!f1(x)) {
        x.a //OK
    }
}
type Cond<S> = S extends number ? B<S> : C<S>
type U2<S> = A<S> | Cond<S>
function f2<S>(u: U2<S>): u is Cond<S> {
    return false
}
function test2<S>(x: U2<S>) {
    if (!f2(x)) {
        x.a //ERROR
    }
}π Actual behavior
The type guard is unable to narrow the type of x to A
π Expected behavior
The type guard should narrow the type of x to A because it is not assignable to Cond<S>
bbenezech, KnorpelSenf and twavv
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed