【问题标题】:What is the type of function in flow javascript type checker?流javascript类型检查器中的函数类型是什么?
【发布时间】:2016-02-14 23:21:48
【问题描述】:

在函数作为参数传入的上下文中,您将如何定义流中函数的类型?例如,下面的 afterDoneSomething 是正在传递的回调函数 - 我不确定我如何使用流定义它的类型。

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

【问题讨论】:

    标签: javascript function flowtype


    【解决方案1】:

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

    所以假设你的afterDoneSomething 接受一个数字并返回一个数字,它应该被注释为

    function doSomething(path:string, afterDoneSomething: (x: number) => number)
    

    【讨论】:

    • 如果函数没有返回任何东西怎么办?
    • @NikSo () => 无效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 2012-09-14
    • 2021-07-13
    • 1970-01-01
    相关资源
    最近更新 更多