Closed
Description
I'm hoping to be able to properly type functions like Ramda's R.map (for objects) or Lodash's _.mapValues -- in such a way as to acknowledge that mapped over values (which may have been of different types) may give results of different types, dependent on both their respective input type as well as on the mapper function.
Code
let arrayify = <T> (v: T) => [v];
declare function mapObject<T, V, M extends {[k: string]: T}>(func: (v: T) => V, m: M): {[K in keyof M]: V}
// ... or Lodash's _.mapValues, Ramda's R.map / R.mapObjIndexed / R.project...
mapObject({ a: 1, b: 'foo' }, arrayify)
Desired behavior:
{ a: number[], b: string[] }
Actual behavior:
{ a: any[], b: any[] }
I apologize for the use of libraries for this example. Probably more verbose without, but the concept is common in FP libraries.