Skip to content

Return type of constructor signature must be assignable to the instance type of the class #5372

@g162h3

Description

@g162h3

This is very annoying message because it comes without an explanation. Often appears when I convert an existing function-like class into a class-like function to write a proper interface without actually changing the implementation:

class Huge {
  foo: Foo;
  bar: () => Bar;

  constructor(...) {
    ...
    return {
      foo: ...,
      bar: ...
    };
  }
}

The return statement with the entire returned expression is highlighted and this confusing error is given. In many cases I end up commenting/uncommenting parts of the interface to find which members are causing this errors. In some cases I gave up and I had to case the result to any.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions