Thursday, 29 October 2020

ObjMap return value or function

I don't understand why this is not working. I expect $ObjMap to require that the object return the value, or a function that returns that value. See the comment in the code. Anyone know how to make this work?

type TObj = {|
  a: number,
  b: string,
  c: boolean,
|};

type Extract = <V>(V) => (() => V) | V

type TType = $ObjMap<TObj, Extract>

function a (): string {
  return 'a';
}

// Expect a to have an error as it is a function that returns a string.
// $ObjMap states that it must be either a number, or a function that returns 
// a number.
const t: TType = {
  a,
  b: 'v',
  c: true,
};

https://flow.org/try/#0C4TwDgpgBAKg8gIwFZQLxQN4B8BQUoCGAXFAHYCuAtghAE4A0eUCJAzsLQJakDmj+AYxIIA9iIA2EAqUZYAvgG4cOUJCgBRAB4cCA4GigAeAGoA+ABTGAlGlNRz5m6jvWoWKMeWroMGOGjoACSISACyBGCG8Mj0Gtq0usCmygBm5KR6nCKkhPZWbBzcPJhMtBDA5LQ5AOQE1UpyygLZ7FDAJL7+BhhMxIT8zCTVAG7VA0JttOQQjIpAA



from ObjMap return value or function

No comments:

Post a Comment