rescript-lang.org icon indicating copy to clipboard operation
rescript-lang.org copied to clipboard

More explicit documentation `Nullable. fromOption` showing both branches

Open kevgathuku opened this issue 2 months ago • 1 comments

Hello, Just going through the docs and found a minor issue with the Nullable.fromOption documentation which seems a bit incomplete, since it does not show what to expect for the None case

It does show how the Some branch is handled, which is great. Nullable.fromOption documentation

Considering the Nullable type is used for handling both null and undefined values it could be nice to mention or add an example showing what is returned for the None case.

I found out through trial and error that it does return undefined, but it would be nice to have this clearly documented, since it is also reasonable to expect it to return null

Maybe something like this could work?

let nullableString = None
let asNullable = nullableString->Nullable.fromOption // undefined

kevgathuku avatar Dec 05 '25 20:12 kevgathuku

In in the language manual it is also mentioned, but it seems to have the same issues of not being specific with what the fromOption compiles to when operating on None

`Nullable.fromOption` converts from a option to Nullable.t.  Nullable.toOption does the opposite.

I think it would be nice to mention it in both places

kevgathuku avatar Dec 05 '25 21:12 kevgathuku