Skip to content

Type guard failures with negative condition #9861

Closed
@falsandtru

Description

@falsandtru

TypeScript Version: 2.0.0

Code

class A<T> {
  private _: T;
}
class B<T> {
  private _: T;
}
function f() {
  var o: A<void> | B<void> = new B<void>();
  if (!(o instanceof B)) return o; // B<void>, should be A<void>
  o; // B<any>, should be B<boid>
}

Expected behavior:

A type of o narrowed by type guard inside if statement is A<void>.
A type of o narrowed by type guard after if statement is B<void>.

Actual behavior:

A type of o narrowed by type guard inside if statement is A<void>.
A type of o narrowed by type guard after if statement is B<any>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions