Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sandersn opened this issue Apr 15, 2016 · 1 comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@sandersn
Copy link
Member

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.

@sandersn sandersn added Suggestion An idea for TypeScript Discussion Issues which may not have code impact labels Apr 15, 2016
@mhegazy mhegazy added Declined The issue was declined as something which matches the TypeScript vision and removed Discussion Issues which may not have code impact labels Apr 15, 2016
@mhegazy mhegazy closed this as completed Apr 15, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Apr 15, 2016

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.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants