2017-07-11 75 views
1

鑑於這些類型:可能流注釋一個免費的功能?

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

而這種自由點轉換功能fooToBar

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

是否可以詮釋fooToBar的的Foo -> Bar簽名?

回答

2

function type annotation docs非常詳細。它看起來像下面應該爲你

/* @flow */ 

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

const prop = y => x => x[y]; 

const fooToBar : Foo => Bar = prop('bar'); 

Flow says

No errors! 
+1

謝謝合作。它完美的工作! –