f# - FunScript querySelector null result -
i want use document.queryselector
method html node. in js can receive null
result. in f# result type element
, it's neither nullable nor optional , it's not clear how check null
. how can handle situation when queryselector
doesn't match dom node?
yes, it's true f# code assumes element not nullable. can trick compiler think otherwise in several ways. easiest 1 box value this:
let el = globals.document.queryselector(".myclass") if (box el) = null dosomething() else dosomethingelse()`
box
ignored when generating js code, there's no performance penalty in doing this.
Comments
Post a Comment