Javascript语法null:?{}

Ila*_*ang 2 javascript reactjs flowtype react-native

示例 https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/PanResponderExample.js#L41

var PanResponderExample = React.createClass({
  ...
  circle: (null : ?{ setNativeProps(props: Object): void })
  ...
Run Code Online (Sandbox Code Playgroud)

我不知道这是什么意思 circle: (null : ?{ setNativeProps(props: Object): void })

谢谢你的建议.

aar*_*nTw 6

这是流量的类型转换,你可以在这篇文章中看到更多细节

类型转换特别适用于检查假设并帮助Flow推断您想要的类型.这里有些例子:

  (x: number) // Make Flow check that x is a number
  (0: ?number) // Tells Flow that this expression is actually nullable.
  (null: ?number) // Tells Flow that this expression is a nullable number.
Run Code Online (Sandbox Code Playgroud)

那么circle: (null : ?{ setNativeProps(props: Object): void })mean circle属性是一个可以为空的对象,它有一个setNativeProps方法,默​​认值是null.