When using a curried functions that separately accept a function & list, how can the function parameter's parameter be correctly inferred (avoiding inferring as unknown) from the list if the order of currying is accept a function as the first parameter THEN accept a list as the second parameter? - Is this possible? If not, what is the best approach here to provide a good function API to improve the developer experience?
For example, in the below snippet, a selector function is passed as the first parameter to the first curried function, and it's parameter i should provide the type T that provides type inference for the second parameter numbers of the second curried function.
However, select's i parameter is inferred as type unknown - why is this the case?
How can the example be changed so that i's & list's inferred types are both Item?
const select = <T>(selector: (i: T) => T) => (numbers: T[]) => numbers.map(selector);
interface Item { name: string; }
const items: Item[] = [{ name: 'name1' }, { name: 'name2' }];
// ERROR: Property 'name' does not exist on type 'unknown' (`i` is type `unknown`, `items` is type `Item[]`).
select(i => i.name)(items);