Allow specifying only a subset of generic type parameters explicitly instead of all vs none
See original GitHub issueTypeScript Version: 2.3.0 https://www.typescriptlang.org/play/ Code
class Greeter<T, S> {
greeting: T;
constructor(message: T, message2: S) {
this.greeting = message;
}
}
let greeter = new Greeter<string>("Hello", "world");
Expected behavior:
The compiler should infer S
to be string
.
Actual behavior: Error:
Supplied parameters do not match any signature of call target.
The compiler expects either all generic parameters to be specified explicitly or none at all.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:77
- Comments:19 (6 by maintainers)
Top Results From Across the Web
java - How to refactor a method to a generic one accepting ...
So it should be able to accept only those types extending my MyParentEntity but able to specify another type ( List<MyOtherEntity> , List<MyAwesomeEntity>...
Read more >Understanding TypeScript Generics - Smashing Magazine
An introduction to the utilization of Generics in TypeScript with examples grounded in real-world use cases, such as collections, ...
Read more >Constraints on type parameters - C# Programming Guide
The type argument must be a reference type, either nullable or non-nullable. This constraint applies also to any class, interface, delegate, ...
Read more >Built-in Types — Python 3.11.1 documentation
The methods that add, subtract, or rearrange their members in place, and don't return a specific item, never return the collection instance itself...
Read more >Google C++ Style Guide
Consistency also allows for automation: tools that format your code or adjust ... source type as its only argument (or only argument with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I too am currently using currying as well as workaround, but it feels too hacky to me. I wish this can be resolved.
For anyone else wondering about a workaround, as @alshain said you can use currying. The workaround for the above example would be: