Skip to content
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

constructor call. Method cannot be called on T. #1760

Closed
cameron-martin opened this issue May 8, 2016 · 3 comments
Closed

constructor call. Method cannot be called on T. #1760

cameron-martin opened this issue May 8, 2016 · 3 comments

Comments

@cameron-martin
Copy link

If I try to typecheck the following code:

function construct<T>(constructor: Class<T>): T {
  return new constructor();
}

I get the following error:

 88:   return new constructor();
              ^^^^^^^^^^^^^^^^^ constructor call. Method cannot be called on
 88:   return new constructor();
                  ^^^^^^^^^^^ T

It seems like this code should be valid.

@vkurchatkin
Copy link
Contributor

Flow has now way of knowing what arguments should be passed to constructor

@cameron-martin
Copy link
Author

Good point. For my use, this will never be able to be safe (probably without dependent types), so I had to cast constructor to any.

@vkurchatkin
Copy link
Contributor

@cameron-martin See: #1409. To avoid any you can pass factory function instead of constructor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants