Skip to content

Functions with a declared this type should return that type when called with 'new' #8109

Closed
@sandersn

Description

@sandersn

Given

interface FooType {
  x: number;
}
function Foo(this: FooType, x: number) {
  this.x = x;
}
let foo/**/ = new Foo(12);

Expected:
foo should be of type FooType

Actual:
foo is of type any.

Note: If you name the interface and the function the same thing, then the type of foo is structurally correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions