Skip to content

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

Closed

Description

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.

Activity

  1. added
    DeclinedThe issue was declined as something which matches the TypeScript vision
    and removed
    DiscussionIssues which may not have code impact
    on Apr 15, 2016
  2. mhegazy commented on Apr 15, 2016

    @mhegazy
    Contributor

    As per the discussion in the design meeting today, we should log a new issue for supporting new syntax for defining a function that can be called as a constructor.

  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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