How do I type a function with input and output objects with the same keys but different value types?

Viewed 2268

Basically, I have a function that will transform an object into a different object, and it's like a dictionary, but I don't know how to type it.

var myFunctions = {
  a: () => something1,
  b: () => something2,
  [...]
}

gets transformed into

var myObject = {
  a: something1,
  b: something2
  [...]
}
3 Answers

With Flow 0.33+ you can use $ObjMap

type ExtractCodomain = <V>(v: () => V) => V;
declare function f<O>(o: O): $ObjMap<O, ExtractCodomain>;
Related