这个问号在Flow中意味着什么:“?()=>空隙" [英] What does this question mark mean in Flow: "?() => void"
问题描述
在 GitHub项目中我最近看到了这个函数声明:
In a GitHub project I recently saw this function declaration:
function configureStore(onComplete: ?() => void) {
这个问号是关于什么的?
What this question mark is about?
我想, onComplete
是命名参数,获取函数调用。问号是声明这个参数可以是可选的,并且默认为void,这意味着像nil / null指针一样意味着这里指的是无闭包。
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.
我是对的吗?
推荐答案
差不多。
()=> void
是一个不返回任何内容的函数的Flow注释( undefined
,又名 void 0
) 。
() => void
is Flow's annotation for a function that returns nothing (undefined
, aka void 0
).
中的主要问号?MyType
是Flow表达可空类型的方式。
The leading question mark in ?MyType
is Flow's way of expressing a nullable type.
所以在这种情况下 configureStore
接受一个名为 onComplete
的参数,它必须是null或不返回任何内容的函数。
So in this case configureStore
accepts one argument called onComplete
that must be either null or a function that returns nothing.
Flow不会为<$ c $ c> onComplete 添加默认值或强制它方式因为与typescript不同,Flow不会生成任何新的JS代码。在运行时,所有Flow注释都被剥离以获得vanilla JS,就是这样。
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.
这篇关于这个问号在Flow中意味着什么:“?()=>空隙"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!