microsoft / microsoft/TypeScript
Generic type inference failure in a union.
Open
Nobody has claimed this yet.
Bug
Domain: check: Type Inference
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.3.0-dev.20190117
Search Terms: generic type inference, union types
Code
function f1<A1, B1>(cb: (a: A1, b: B1) => void) {
f2(cb); // I expect no errors
}
function f2<A2, B2>(cb: ((x: number, a: A2, b: B2) => void)|
((a: A2, b: B2) => void)) {} // If I swap the two types it compiles
Expected behavior:
No errors.
Actual behavior:
TS2345: Argument of type '(a: A1, b: B1) => void' is not assignable to parameter of type '((x: number, a: B1, b: B1) => void) | ((a: B1, b: B1) => void)'.
Type '(a: A1, b: B1) => void' is not assignable to type '(x: number, a: B1, b: B1) => void'.
Types of parameters 'a' and 'x' are incompatible.
Type 'number' is not assignable to type 'A1'.
Related Issues:
I looked around and didn't anything obviously related.
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 reproducing the generic inference failure in the TypeScript Playground link using TypeScript 3.3.0-dev.20190117, then compare the behavior when the union members are reordered. Done means the shown call to f2 produces no error while preserving the expected generic parameter inference.
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
- 35/100