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

Allow declare generics for function expressions #561

Closed
MaxGraey opened this issue Mar 27, 2019 · 3 comments
Closed

Allow declare generics for function expressions #561

MaxGraey opened this issue Mar 27, 2019 · 3 comments

Comments

@MaxGraey
Copy link
Member

var pass = <T>(a: T): T => a
@dcodeIO
Copy link
Member

dcodeIO commented Mar 28, 2019

For a bit of background: I initially excluded this at the parser level because such a function isn't represented by a concrete value until fully resolved, so there's nothing to pass around, i.e. when calling a function with a generic function expression as an argument, or just store it in var pass. To me it looks like it's rather a type than a function, and its existence is strictly tied to the dynamic nature of JS. Not saying "no" ofc, but that's the reasoning so far :)

@MaxGraey
Copy link
Member Author

Btw this code also produce error:

var pass = <T>(a: T): T => a;
pass<i32>(1);

Output:

ERROR TS2304: Cannot find name 'T'.

and later:

ERROR TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'i32' has no compatible call signatures.

@dcodeIO
Copy link
Member

dcodeIO commented May 27, 2020

Closing this issue as part of 2020 vacuum because it seems unlikely that we can solve this statically anytime soon due to a missing opportunity to represent it. If someone has an idea that doesn't involve costly runtime checks or otherwise including metadata, feel free to open a new issue or reopen this one.

@dcodeIO dcodeIO closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants