`getElementById` is unsafe
Hi, I was trying out F# recently and encountered a runtime error when using getElementById due to the return type being HTMLElement but not option<HTMLElement>.
Thanks for pointing this out. We had this discussion before (I forgot where so I don't have a link, sorry), but the conclusion was in general we're not using option to represent anything that can be null in JS. One of the reasons is that when we converted the fable-browser bindings from .d.ts declarations, Typescript wasn't "null safe" yet, so it was difficult to know which APIs could return null values without checking one by one. Maybe we could try to do it now but it may cause several breaking changes.
For now you can just do a null check as you would do in JS, either with isNull op pattern maching:
match document.getElementById "my-id" with
| null -> // do something
| el -> // do something else
Once https://github.com/dotnet/fsharp/pull/15181 lands, we should be able to indicate nullability in bindings. Hopefully the latest compiler and lang version switch will be enough (both on the side of this repo and user projects).