Skip to content

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

Open
@MaksiRose

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

declare class Foo<Stuff extends boolean> {
  stuff: Stuff extends true ? string : string | undefined;
  isReady(): this is Foo<true> 
}
declare const x: 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

    Possible 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