microsoft / microsoft/TypeScript
[Regression 3.9 -> 4.X] Variadic tuple type is not correctly inferred
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
variadic tuple, regression, inference
🕗 Version & Regression Information
- This changed between versions 3.9.X and 4.X.X
⏯ Playground Link
Typescript 3.9 (works as expected)
Typescript 4.0 (does not work any more)
💻 Code
type Sink<T> = (t: number, payload: T) => void;
type Producer<T> = (t: number, sink: Sink<T>) => void;
type ExtractContent<T extends [Producer<unknown>, ...Producer<unknown>[]]> = {
[k in keyof T]: T[k] extends Producer<infer U> ? U : never;
}
function combineWith<T extends [Producer<unknown>, ...Producer<unknown>[]], U>(
fn: (...args: ExtractContent<T>) => U,
...sources: T
): Producer<U> {
return undefined as any;
}
function of<T>(n: T): Producer<T> {
return undefined as any;
}
const x = combineWith((x, y) => x + y, of(1), of(2));
With typescript 3.9, the arguments of the lambda passed to combineWith are correctly read as (number, number). With 4.0 everything is just unknown, even the Producer arguments later
🙁 Actual behavior
x and y (of the lambda function) are types unknown
🙂 Expected behavior
x and y (of the lambda function) are types number
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 with the linked TypeScript 3.9 and 4.0 Playground reproductions and the combineWith, ExtractContent, Producer, and of definitions in the issue. Compare inference behavior between versions and confirm completion when the callback parameters and later Producer arguments infer as number rather than unknown.
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
- Clearly specified
- Newbie friendliness
- 25/100