ope*_*eek 9 javascript function flowtype
在函数作为参数传入的上下文中,如何为flow中的函数定义类型?例如,afterDoneSomething下面是回调函数,它已经通过了 - 我不知道我是如何用流定义它的类型的.
function doSomething(path:string, afterDoneSomething:<What is the Type>)
Run Code Online (Sandbox Code Playgroud)
Lim*_* H. 11
根据文档:http://flowtype.org/docs/functions.html,您需要提供函数的参数类型和返回值:(P1: T1, .., Pn: Tn) => U
因此,假设您afterDoneSomething接受一个数字并返回一个数字,它应该注释为
function doSomething(path:string, afterDoneSomething: (x: number) => number)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3842 次 |
| 最近记录: |