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?
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?
Share Improve this question edited May 16, 2016 at 17:35 Michał Perłakowski 92.6k30 gold badges163 silver badges186 bronze badges asked May 16, 2016 at 16:52 deletedelete 19.2k17 gold badges62 silver badges98 bronze badges 6- No; that's a type. – SLaks Commented May 16, 2016 at 16:54
- Can you explain it a litte more to me pls? (or send a link to docs; i already search at google but did not find anything about) – delete Commented May 16, 2016 at 17:04
- 1 I guess it's either flow or typescript. flowtype, typescriptlang – Felix Kling Commented May 16, 2016 at 17:08
-
5
?
indicates that this is Flow nullable type and not TypeScript. – Estus Flask Commented May 16, 2016 at 17:11 - I just added the URL to the github project. And here also: github./fbsamples/f8app/blob/… – delete Commented May 16, 2016 at 17:19
1 Answer
Reset to default 17Almost.
() => 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.