-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed as not planned
Labels
SuggestionAn idea for TypeScriptAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it addsAn issue which adding support for may be too complex for the value it adds
Description
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
myImplicitlyCalledMethod = <T>(someVar: any): T => {
let b:T;
//Code that converts someVar to T or create an object with type T from someVar
return b;
}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.
myCallingMethodWithoutTyping = (someVar:any) => this.myImplicitlyCalledMethod;
myCallingMethodWithTyping = (someVar:any) => this.myImplicitlyCalledMethod<number>(someVar);Expected behavior:
This is what I would like to be able to do :
myCallingMethodWithoutTyping = (someVar:any) => this.myImplicitlyCalledMethod<number>;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
- Syntactic: Allow declaring of generics in implicitly called methods
- Semantic: Should not change the core logic of typescript, or anything.
- Emit: Emitted code would not change, it would simply be to help with declaring types with less code.
- Compatibility: Code using this wouldn't be backwards compatible.
- Other:
- Performance: This might affect performance depending on how it's implemented.
- Tooling: Would actually help with inferred typing
aluanhaddad, billba, fjozsef and dolsem
Metadata
Metadata
Assignees
Labels
SuggestionAn idea for TypeScriptAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it addsAn issue which adding support for may be too complex for the value it adds