Consider the following code with external FFI which works fine:
type operatorFunc
external _debounceTime : int -> ?hasSchedular:bool -> unit -> operatorFunc = "debounceTime"
[@@bs.module "myModule"]
let debounceTime1 = _debounceTime 1000 ()
However, if try to create a wrapper function (with an optional argument) around _debounceTime, then it doesn’t work:
let debounceTime ?hasSch () = _debounceTime 1000 ~hasSchedular:hasSch ()
(* ERROR: This expression has type 'a option but an expression was expected of type bool *)
Of course, trying to use pattern matching on hasSch yields a warning which is right:
let debounceTime ?hasSch =
match hasSch with
| None -> _debounceTime 1000 ()
| Some a -> _debounceTime 1000 ~hasSchedular:a ()
(* Warning 16: this optional argument cannot be erased. *)
The question here is - what is the idiomatic way to pass one optional function argument to another external function?