Skip to content

Type guard failures that become an intersection type #9859

Closed
@falsandtru

Description

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 A) return o; // B<void> & A<any>, should be A<void>
}

Expected behavior:

A type of o narrowed by type guard is A<void>.

Actual behavior:

A type of o narrowed by type guard is B<void> & A<any>.

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions