[英]Typescript Type Assertion operator precendence
我应该在'as'类型断言上包装js-三元运算符吗?
ios ? TouchableOpacity : View as React.ElementType
或者,因为它总是“先来”,它将使用 '?:' 结果?
或更好的实施将:
(ios ? TouchableOpacity : View) as React.ElementType
a ? b : c as T
a ? b : c as T
等价于a ? b : (c as T)
a ? b : (c as T)
。
Math.random() > .5 ? '' : 0 as string
// ~~~~~~~~~~~
// Conversion of type 'number' to type 'string' may be a mistake...
// Ok
(Math.random() > .5 ? '' : 0) as string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.