Repository navigation
Inferring types: curried vs not curried #15005
Description
Activity
Type inference will also work with this declaration:
declare function props<P1 extends string, P2 extends string, O extends {[K in P1 | P2]: any}> (ps: [P1, P2], obj: O): [O[P1], O[P2]];
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.Reacted by Aluan Haddad and AlexPyroVortex
Is it possible for this case to limit ps tuple size to 2? Or prohibit props that are not inobjSo it wouldn't allow:
// should be an error, as 'whatever' is not in {a: 1, b: '2'}` props(['a', 'b', 'whatever'])({a: 1, b: '2'})[0]
- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on May 24, 2017 I run into similar problem:
declare const a: { cb: (arg: number) => void } declare function test1<T>(a: T, b: T): void; test1(a, { cb(arg) { } }) // parameter 'arg' implicitly has an 'any' type declare function test2<T>(a: T, b: () => T): void; test2(a, () => ({ cb(arg) { } })) // parameter 'arg' implicitly has an 'any' type declare function test3<T>(a: T): (b: T) => void // curried test3(a)({ cb(arg) { } }) // (parameter) arg: number declare function test4<T>(a: T): (b: () => T) => void // curried test4(a)(() => ({ cb(arg) { } })) // (parameter) arg: number
Looks like there're some related issues: #23429, #22715 #25092
Reacted by Sergey Cherepanov- addedQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in codeand removedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Sep 16, 2019 typescript-bot commented
on Sep 21, 2019 ContributorMore actionsThis 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.
Reacted by Kirill Agalakov- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
TypeScript Version: 2.2.2
This possible typings of props function from ramda for two arguments:
I wonder why if second object argument is not curried TS can not infer types in results:
And when curried it can:
Is TS going to make it work in future?