microsoft / microsoft/TypeScript
Inferred type is not the same as what's passed in original generic type.
Open
Nobody has claimed this yet.
Bug
Domain: check: Type Inference
Effort: Difficult
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
🔎 Search Terms
infer, generic
🕗 Version & Regression Information
- This is a crash
- This changed between versions _________ and _________
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about infer.
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
// The variable names are meaningless, they are simplified from vue project.
type PropConstructor<T = any> =
| { new (...args: any[]): T & object }
| { (): T }
type MyInfer<T> = T extends PropConstructor<infer V> ? V : 'xxx'
type VVV = (() => string) | (() => number)
type X = MyInfer<PropConstructor<VVV>>
🙁 Actual behavior
type X = (() => string) | (() => number) | ((() => string) & object) | ((() => number) & object)
🙂 Expected behavior
type X = (() => string) | (() => 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 by running the linked TypeScript Playground examples and comparing the inferred type X with the reported actual and expected types. The work is complete when the generic inference behavior for MyInfer<PropConstructor> matches the expected union without the additional intersections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100