Newcomer Examples
An example is worth a thousand words.
This section is dedicated to newcomers trying to figure out general idioms & conventions. If you're a beginner who's got a good idea for an example, please suggest an edit!
Use the option
type
Create a Parametrized Type
Creating a JS Object
Or using record:
Modeling a JS Module with Default Export
See here.
Checking for JS nullable types using the option
type
For a function whose argument is passed a JavaScript value that's potentially null
or undefined
, it's idiomatic to convert it to an option
. The conversion is done through the helper functions in ReScript's Nullable
module. In this case, toOption
:
This check compiles to possiblyNullName == null
in JS, so checks for the presence of null
or undefined
.