Search code examples
javascriptfunctional-programmingflowtypepointfree

Possible to flow-annotate a point-free function?


Given these types:

type Bar = number;
type Foo = {
  bar: Bar,
};

And this point-free conversion function fooToBar:

import { prop } from 'ramda';
const fooToBar = prop('bar');

Is it possible to annotate fooToBar's signature of Foo -> Bar?


Solution

  • The function type annotation docs are pretty detailed. It looks like the following should work for you

    /* @flow */
    
    type Bar = number;
    type Foo = {
      bar: Bar,
    };
    
    const prop = y => x => x[y];
    
    const fooToBar : Foo => Bar = prop('bar');
    

    Flow says

    No errors!