Void" In the GitHub project I recently saw this function declaration: function configur...">

What does this question mark mean in the stream: "? () => Void"

In the GitHub project I recently saw this function declaration:

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

What is this question mark?

I think onComplete has a parameter name, receiving function calls. And the question mark indicates that this parameter may be optional and will default to "void", which will mean the same as the nil / null pointer, which means "no clos" here.

I'm right?

+6
source share
1 answer

Nearly.

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

The leading question mark in ?MyType is the way that an expression of type NULL is ?MyType .

So, in this case, configureStore takes a single argument called onComplete , which must be either null or a function that returns nothing.

The stream will not add a default value for onComplete or force it in any way, because unlike typescript, Flow does not generate new JS code. At run time, all Flow annotations are removed to get vanilla JS, and what it is.

+16
source

All Articles