Skip to content

Type Guards are no longer working correctly all the time #54178

Description

@MaksiRose

Bug Report

🔎 Search Terms

Type Guard

🕗 Version & Regression Information

  • This changed between versions 4.9.5 and 5.0.4

⏯ Playground Link

A simple example

💻 Code

declareclassFoo<Stuffextendsboolean>{stuff: Stuffextendstrue ? string : string|undefined;isReady(): this is Foo<true>}declareconstx: Foo<boolean>;if(x.isReady()){x//^? - const x: Foo<boolean>// Should be Foo<true>}

🙁 Actual behavior

The Type Guard didn't change the type, which is unintuitive behavior.

🙂 Expected behavior

The method should act as a type guard and change the type

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: This-TypingThe issue relates to providing types to thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions