Microsoft/TypeScript
GitHub ã§èŠãInferred type is not the same as what's passed in original generic type.
Open
#42,516 opened on 2021幎1æ27æ¥
BugDomain: check: Type InferenceEffort: DifficultHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
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))