Javascript语法为null:?{} [英] Javascript syntax null : ?{}

查看:61
本文介绍了Javascript语法为null:?{}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

var PanResponderExample = React.createClass({
  ...
  circle: (null : ?{ setNativeProps(props: Object): void })
  ...

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

I don't know what does it mean circle: (null : ?{ setNativeProps(props: Object): void })

谢谢您的建议.

推荐答案

它是 flow 的类型转换,您可以在此帖子

It's flow's typecasts, you can see more details in this post

类型转换对于检查假设和帮助Flow推断您想要的类型特别有用.以下是一些示例:

Typecasts are particularly useful to check assumptions and help Flow infer the types you intend. Here are some examples:

  (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.

所以circle: (null : ?{ setNativeProps(props: Object): void })表示circle属性是可为空的对象,该对象具有setNativeProps方法,默认值为null.

so circle: (null : ?{ setNativeProps(props: Object): void }) is mean circle property is a nullable object which have a setNativeProps method and default value is null.

这篇关于Javascript语法为null:?{}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆