false. The former compiles to
1 (don't rely on this from the JS side).
The type for BuckleScript boolean is
bool. The type for JS boolean is
Js.to_bool converts from JS
boolean to BS
Js.Boolean.to_js_boolean is the opposite.
Tips & Tricks
If you mark an
external as returning
bool, we automatically understands it as wanting to return a
Js.boolean (since the JS side can never return a BuckleScript
bool), and will do an implicit conversion:
external isStudent: string -> bool = "isStudent" [@@bs.val]
[@bs.val] external isStudent : string => bool = "isStudent";
bs.val is a frequent annotation for binding to values. It'll be introduced in the next section.
You don't have to use
string -> Js.boolean and then do an explicit conversion though
The implicit conversion's cost is also very small; BS will even remove such coercion when not needed.
bool mapping to
boolean would have been an obvious feature, given that we do the same for string, float, array, etc. Unfortunately, due to some existing limitations in the architecture, we can't do this yet.