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
I wonder why if second object argument is not curried TS can not infer types in results:
declarefunctionprops<P1extendsstring,P2extendsstring,T1,T2>(ps: [P1,P2],obj: {[KinP1]: T2}&{[KinP2]: T2}): [T1,T2];props(['a','b'],{a: 1,b: '2'})[0]=>// can not infer `number` typeprops(['a','b'],{a: 1,b: '2'})[1]=>// can not infer `string` type
And when curried it can:
// this is inferreddeclarefunctionprops<P1extendsstring,P2extendsstring>(ps: [P1,P2]): <T1,T2>(obj: {[KinP1]: T1}&{[K2inP2]: T2})=>[T1,T2];props(['a','b'])({a: 1,b: '2'})[0]=>// this can infer `number` typeprops(['a','b'])({a: 1,b: '2'})[1]=>// this can infer `string` type
In your first example, the mapped types for obj are additional inference sites for P1 and P2, which results in them being both inferred as 'a' | 'b'. In the curried case, P1 and P2 are fixed as 'a' and 'b', respectively, when the second function gets called, and therefore limit what each of the two intersected types matches.
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.
Activity
PyroVortex commentedon Apr 4, 2017
Type inference will also work with this declaration:
In your first example, the mapped types for
objare additional inference sites forP1andP2, which results in them being both inferred as'a' | 'b'. In the curried case,P1andP2are fixed as'a'and'b', respectively, when the second function gets called, and therefore limit what each of the two intersected types matches.wclr commentedon Apr 5, 2017
PyroVortex
Is it possible for this case to limit ps tuple size to 2? Or prohibit props that are not in
objSo it wouldn't allow:
raveclassic commentedon Oct 17, 2018
I run into similar problem:
Looks like there're some related issues: #23429, #22715 #25092
chore(react-kit): make withRX curried for better type inference micro…
feat(react-kit): accept defaultProps in withrx selector result (#83)
typescript-bot commentedon Sep 21, 2019
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.