Flow: Correct annotation / type for functions (callbacks)

Created on 7 Feb 2015  路  3Comments  路  Source: facebook/flow

Is there a mechanism for specifying the type of a function parameter? For example in this completely contrived example, I'd like to say the the type of the cb argument is not any, but rather _a function that takes a number and doesn't return any value_.

function do_something_async(cb : any) {
        cb(37);
}

Most helpful comment

You mean something like

function do_something_async(cb : (x: number) => void) {
        cb(37);
}

Docs are here, but probably could be improved

All 3 comments

You mean something like

function do_something_async(cb : (x: number) => void) {
        cb(37);
}

Docs are here, but probably could be improved

My bad. Didn't read carefully enough. Thanks for the explicit pointer.

@gabelevi
Well, it's all very nice in theory, however, it does not work with Flow v0.12.0

function type
This type is incompatible with
/private/var/folders/_1/90xwg0pd17j8qfn91lmj7t6h0000gn/T/flow/flowlib_381eedd4/lib/core.js:57:1,63:1: Function
Was this page helpful?
0 / 5 - 0 ratings