-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use more option
types in the bindings?
#21
Comments
It's true that Fable erases optional types and we do use IIRC Typescript didn't have nullable types when we use the original declarations to generate the bindings, and I was using MDN documentation for the latest update. Moreover, nullable reference types are coming to F#, this may be a better opportunity to update the bindings with better compatibility and less breaking changes. |
Ah, I didn't know about nullable types and AFAIK BuckleScript guarantees that for |
Yes, it works more or less the same in Fable :) https://github.com/fable-compiler/Fable/blob/55904c4cf291df63287c1d2899b56b349e70f67f/src/Fable.Transforms/Transforms.Util.fs#L326-L331 If your primary target is to interact with JS in a type-safe way, I'd recommend using Typescript. This is a language created with that target as its main goal. Fable was created just to be able to program for the JS platform in F#. We try to make JS interop easier but you will still encounter many more friction points that when using Typescript. |
Considering that ts2fable generates
Not exactly. I do use TypeScript for those use cases but I'm trying to decide between F# and OCaml (BuckleScript). I really like the syntax and features of F# but I'm still learning the ecosystem. |
Sorry for the late reply, I somehow missed the notification of your last comment. Yes, backward compatibility is a big factor as we had several breaking changes in latest release and this obviously annoys users. Also, if we were to make this change I'd like to wait a bit until nullable references come to F# (seems it'll happen soon) to see if they're a better fit for this case (although in Fable we'll probably still have issues with numbers and other value types, as they can also be null in JS).
As mentioned above, it will probably work in 99% of cases, but Fable is wrapping options in a few cases as for generic parameters (because they may become nested options). |
Is there any reason why functions which can return
null
in JS (e.g.document.querySelector
) are not typed as returningoption
values? With the current types it's trivial to get runtime errors which I wouldn't expect from a statically typed language that compiles to JS. In TypeScript that function returnsElement | null
which means the user cannot call methods on it without checking that it's notnull
. In OCaml (BuckleScript) it returnsDom.element option
. I would expect the same in F#.cc @nojaf who suggested I open an issue here
The text was updated successfully, but these errors were encountered: