[英]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.