-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Declaring generic type of implicitly called method #15877
Comments
Definitely interesting. Do you see this extending to other kinds of values? |
I'm unsure what you mean by value, by my main usecase would be to use through Rxjs observables in angular to reduce the amount of what I consider to be useless code, for examble being a simple api call going from : this.http.get(url, options)
.map((res)=>this.extractApiResponse<someType>(res))
.catch(this.handleError); to : this.http.get(url, options)
.map(this.extractApiResponse<someType>)
.catch(this.handleError); Which I personally find better, and would allow me to do as much with less code. Granted it's not much code, but when you write a slight variation of this 2-5 times a day it gets tedious. |
The expected behavior I personally am looking for is around functions, not methods, but same idea applies: const myCallingFunctionWithoutTyping = myImplicitlyCalledFunction<any>;
const myCallingFunctionWithTyping = myImplicitlyCalledFunction<number>; In my head I sometimes try to replace alias myCallingFunctionWithoutTyping = myImplicitlyCalledFunction<any>;
alias myCallingFunctionWithTyping = myImplicitlyCalledFunction<number>; But in the end I'd be happy with just making them variables, because it solves the problem. |
This seems to have gone quiet for a while. Is there any news as to whether this is planned for being implemented? Thanks |
There is a lot to be worked out here before it'd be actionable. Functions can be overloaded, and generics can have defaults, so it's not entirely clear what |
As far as overloading, it seems like |
there was an issue about generic namespaces #19728 but it was closed in favor of this one, so I have interesting case I think. namespaces are interesting in context of generics, because namespaces can hold types, like type aliases. but I thing that what I want to achieve could be awkward with namespaces basically I want o have a type "constructor", or template, that is in types realm not values realm.
this also is interesting
then I could do
and then later I could use
what do you think about it? |
I think this would reasonably be subsumed by #17574 so doesn't need to exist as a one-off feature that'd be almost the same amount of work for a lot less value |
This issue has been marked as "Too Complex" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
This is a feature request. I am unaware of any recent similar requests
For typing purposes and simple code, it would be good to be able to declare generics of implicitly called methods.
TypeScript Version: Any under 2.3.x at time of writing
Code Example
Take the following method
Actual behavior:
Right now when you call a method with a generic type implicitly, you cannot declare the type directly.
The following code is what I have to do to get the type, along with an implicit call of the method.
Expected behavior:
This is what I would like to be able to do :
The code however throws an exception while compiling as it expects you to pass the parameter when you declare the type of the generic.
Language feature checklist
The text was updated successfully, but these errors were encountered: