You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Second infer overwrites initally infered type defintion #32389
Your workaround makes the second parameter a generic function, which will behave differently. For example this would not be legal:
typeInfer1<T>=()=>T;typeInfer2<T>=TextendsArrayLike<infer S>
? <SSextendsS>(s: SS)=>Partial<SS>
: <TTextendsT>(t: TT)=>Partial<TT>;declarefunctionf<T>(infer1: Infer1<T>,infer2: Infer2<T>): void;declarefunctionf1(): {a: any};f(f1,(s)=>({a: 1}));// concrete value assigned to a generic type not allowed.
See #30134 - the particular use of depending on an infer in a conditional type simultaneously while doing an outer generic inference isn't well-supported in the current algorithm.
Activity
clentfort commentedon Jul 14, 2019
Here is a more minimal example
I expect
f1to be a valid input tofbut TypeScript complains about it.http://www.typescriptlang.org/play/#code/C4TwDgpgBAkgdgMwgJwIwB4AqA+KBeKACgEp9dMBuAKFElkRQCYtcDMoIAPYCOAEwDOUAILJkAQxAAZAJYBrCOhkNkUAMrYqUKAH4i4gFzrSeXAAVxyYDPEAbdBq1QjhQ1Ewnzl63ZbUqfBAAxraW0AgArnBB1gD2cFAILITKSGhG8GkYOAA0UKlMGSrMOMRGAG6xMnzUgSFhiVExMvGJqCRGohIg6ADeUG7icCBQAL7Y-giECKh54mQDxNRAA
Interestingly this modified example, where
Infer2does not return a function, works as expected http://www.typescriptlang.org/play/#code/C4TwDgpgBAkgdgMwgJwIwB4AqA+KBeKACgEp9dMBuAKFElkRQCYtcDMoIAPYCOAEwDOUAILJkAQxAAZAJYBrCOhkNkUAMrYqUKAH51WqAC4olKlT4QAxgBtxyaAgCucS8BkB7OFAQtCypGjG8AEYOAA0UP5MQSrMOMTGAG7uMnzUFjZ2Ds6uHl4IqCTGohIg6ADeUOLG4nAgUAC+2NRUCIQFEeXVUKgNxNRAAclentfort commentedon Jul 16, 2019
I found a workaround that at least for now solves my problem by changing
Infer2to the followingI'm not sure if this could have undesired side-effects, but at least it allows me to continue.
dragomirtitian commentedon Jul 16, 2019
Christian Lentfort (@clentfort) If you want a workaround using
& {}will decrease the priority of the second inference site:link
Your workaround makes the second parameter a generic function, which will behave differently. For example this would not be legal:
clentfort commentedon Jul 16, 2019
Thanks for pointing this out, this means my workaround is exactly what I want. :)
RyanCavanaugh commentedon Jul 31, 2019
See #30134 - the particular use of depending on an
inferin a conditional type simultaneously while doing an outer generic inference isn't well-supported in the current algorithm.