Skip to content

Type guard of union with conditional type not working since 4.3#44382

@pedro-pedrosa

Description

@pedro-pedrosa

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

interfaceA<S>{a: S}interfaceB<S>{b: S}interfaceC<S>{c: S}typeU1<S>=A<S>|B<S>|C<S>functionf1<S>(u: U1<S>): u is B<S>|C<S>{returnfalse}functiontest1<S>(x: U1<S>){if(!f1(x)){x.a//OK}}typeCond<S>=Sextendsnumber ? B<S> : C<S>typeU2<S>=A<S>|Cond<S>functionf2<S>(u: U2<S>): u is Cond<S>{returnfalse}functiontest2<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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions