流javascript类型检查器中的函数类型是什么?

时间:2015-11-13 11:27:07

标签: javascript function flowtype

在函数作为参数传入的上下文中,如何为flow中的函数定义类型?例如,afterDoneSomething下面是回调函数,它已经过了 - 我不确定我是如何用流定义它的类型的。

function doSomething(path:string, afterDoneSomething:<What is the Type>)

1 个答案:

答案 0 :(得分:9)

根据文档:http://flowtype.org/docs/functions.html,您需要提供函数的参数类型和返回值:(P1: T1, .., Pn: Tn) => U

假设你的afterDoneSomething取一个数字并返回一个数字,它应注释为

function doSomething(path:string, afterDoneSomething: (x: number) => number)
相关问题