简体   繁体   中英

What does this question mark mean in Flow: “?() => void”

In a GitHub project I recently saw this function declaration:

function configureStore(onComplete: ?() => void) {

What this question mark is about?

I guess, onComplete is named parameter, getting function calls. And the question mark is stating that this parameter could be optional and will default to "void", which would mean the same like a nil/null pointer what means "no closure" assigned here.

Am I right?

Almost.

() => void is Flow's annotation for a function that returns nothing ( undefined , aka void 0 ).

The leading question mark in ?MyType is Flow's way of expressing a nullable type.

So in this case configureStore accepts one argument called onComplete that must be either null or a function that returns nothing.

Flow will not add a default value for onComplete or coerce it in any way because unlike typescript, Flow does not generate any new JS code. At runtime, all Flow annotations are stripped to get vanilla JS, and that's that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM