Skip to content

Wrong type of class instance if the constructor returns different class instanceΒ #50126

Closed
@Tomas2D

Description

@Tomas2D

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class A {
    greet() {}
}

class C {
  constructor() {
      return new A();
  }
}

let instance: A = new C() // error

πŸ™ Actual behavior

Property 'greet' is missing in type 'C' but required in type 'A'.(2741)

πŸ™‚ Expected behavior

I think that compiler should infer that the constructor will return an instance of a different class

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions