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

前端 未结 1 1459
一整个雨季
一整个雨季 2021-01-13 00:31

In a GitHub project I recently saw this function declaration:

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

What this question mark

相关标签:
1条回答
  • 2021-01-13 00:54

    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.

    0 讨论(0)
提交回复
热议问题