-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Lambda generics are inaccessable inside lambda body #55617
Comments
Your lambda I believe what you want (infer the existence of the generic argument based on the context) would require #47599. n your real world example you can resolve it by declaring the existence of a type argument: /**
* @template P,R
* @type ...
*/ |
What @MartinJohns said; to be clear, what you've done is assigned a non-generic function There is a potential bug here, though: |
It maybe makes more sense why const f = (_: unknown) => {
type A = T // error, what even is T here
};
const b: <T>(_: T) => void = f; |
The inner function actually is being inferred as a generic function - based on the context. See those lines: It actually makes sense. If we hover over const test1: <T>(_: T) => void = function inner(_) {}; Without it, we wouldn't be able to write this: const identity: <T>(arg: T) => T = arg => arg So |
So Martin was wrong and it is inferring the existence of (anonymous) type parameters? I guess that makes sense but it's not really useful if you have no way to refer to them. Hence this issue, I guess. |
Isn't the |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
access generic type inside lambda function body
π Version & Regression Information
5.3.0-dev.20230831
β― Playground Link
No response
π» Code
π Actual behavior
Currently if you define a function as a lambda expression and the type of this lambda is inferred from the type of the variable it's assigned to, attempting to access generic types within the lambda's body results in an error message.
π Expected behavior
TypeScript to permit the use of generic types within the body of a lambda expression, regardless of whether the lambda's type is explicitly defined or inferred from the variable it's assigned to.
Additional information about the issue
Real world example:
Quite often, extracting generic types from parameter types may be challenging since it requires deconstruction of the parameter type. Furthermore, the laziness of type inference can frequently make the result type unusable.
The text was updated successfully, but these errors were encountered: