microsoft / microsoft/TypeScript
Void parameter still required when type extends generic
Open
Nobody has claimed this yet.
Bug
Domain: Conditional Types
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the minimal generic conditional-type example from the issue with TypeScript 3.2.2 and compare it with the non-generic cases. Trace how the compiler determines whether the second parameter is required for fails<1> and fails<2>; done means the generic void case accepts the omitted argument while the number case still requires it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100