Void parameter still required when type extends generic
See original GitHub issueTypeScript Version: 3.2.2
Search Terms: void parameter type extends generic Code
function works1(n: number, b: void) { }
works1(12);
function works2(n: number, b: 1 extends 1 ? void : number) { }
works2(12);
function fails<T>(n: number, b: T extends 1 ? void : number) { }
fails<2>(12, 2); // works, requires both params
fails<1>(12); // fails, requires 2 parameters even though second param is void
Expected behavior: That I can ignore the second parameter since its void
Actual behavior: Ts tells me I am missing a parameter
Issue Analytics
- State:
- Created 5 years ago
- Reactions:19
- Comments:11 (2 by maintainers)
Top Results From Across the Web
java - Understanding generic parameters with void return types
I'm reviewing the source code for JDK classes. The following method signature has me confused: public static <T extends Comparable<? super ...
Read more >Restrictions on Generics (The Java™ Tutorials > Learning the ...
Because the Java compiler erases all type parameters in generic code, you cannot verify which parameterized type for a generic type is being...
Read more >Generics: in, out, where | Kotlin Documentation
Classes in Kotlin can have type parameters, just like in Java: ... { void addAll(Collection<? extends E> items); }. The wildcard type argument...
Read more >Resolving generics in TypeScript
In this article you will find some useful examples of typing factory functions which requires you to use several generics with constraints ...
Read more >Constraints on type parameters - C# Programming Guide
The usefulness of type parameters as constraints with generic classes is limited because the compiler can assume nothing about the type ...
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
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
@parzh You can get the parameter names back (mostly) if you don’t mind writing a bit more:
Playground Link
Variable number of function parameters can still be achieved using tuple types (although, parameter identifiers in IntelliSense will be lost unfortunately):
Link to playground.