TS optional chaining

huangapple go评论135阅读模式
英文:

TS optional channing

问题

renderShimmers 是布尔值或未定义的。如果它是 falseundefined,我希望它是 false。有没有比这更简单的方法?

this.props.renderShimmers ?? false
英文:

renderShimmers is boolean or undefined. I want it to be false if it's false or undefined. Is there a simpler way than this?

this.props.renderShimmers ? this.props.renderShimmers : false

答案1

得分: 3

  • Boolean(this.props.renderShimmers)
  • this.props.renderShimmers || false
  • this.props.renderShimmers ?? false
  • !!this.props.renderShimmers
英文:

Any of these.

  • Boolean(this.props.renderShimmers)
  • this.props.renderShimmers || false
  • this.props.renderShimmers ?? false
  • !!this.props.renderShimmers

huangapple
  • 本文由 发表于 2023年2月27日 17:39:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578811.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定