Skip to content

Bug: Control flow type analysis regression. #11153

Closed
@vagarenko

Description

@vagarenko

TypeScript Version: 2.0.3

This code compiles in TS 1.8 but not in 2.0.3
Code

class A { }
class B { constructor(public b: number) {} }

function foo(x: A | B): number | boolean {
    if (x instanceof A) { return true; }
    else if (x instanceof B) { return x.b; }
    //                                  ^ Property 'b' does not exist on type 'never'.
};

This error only appears if class A has no fields or methods,
if I add a field or a method the error disappears (but not constructor).

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