Rescript-compiler: Ideas: wrap null into option automatically

Created on 14 Feb 2017  路  5Comments  路  Source: rescript-lang/rescript-compiler

extenral match_ : string -> Js.Re.t -> (string array option [@bs.null])
stale

Most helpful comment

@OvermindDL1 I think we make it more general to justify its inclusion

external get : t -> int -> int = "" [@@bs.index]
[@@bs.return { throw_if_null = "error message $0 $1 $2" ; 
                          throw_if_undefined = "xx" ;
                          (* option_if_null ; option_if_undefined ;
                              warn_if_null; warn_if_undefined
                         *) (* these flags are not compatible with [throw]*)
}]

The cool thing is that we can turn on [throw_if_null], [throw_if_undefined] for _FFIs in debug mode_, that will help find FFI bugs quickly.

All 5 comments

That would indeed be quite nice, undefined would still be standalone though?

@OvermindDL1 I think we make it more general to justify its inclusion

external get : t -> int -> int = "" [@@bs.index]
[@@bs.return { throw_if_null = "error message $0 $1 $2" ; 
                          throw_if_undefined = "xx" ;
                          (* option_if_null ; option_if_undefined ;
                              warn_if_null; warn_if_undefined
                         *) (* these flags are not compatible with [throw]*)
}]

The cool thing is that we can turn on [throw_if_null], [throw_if_undefined] for _FFIs in debug mode_, that will help find FFI bugs quickly.

Note we can make the post-assertion a little more general like

type_is_string ? type_is_int? type_is_number? 

Or do it in a best effort style, by doing a console.warn

This would be also useful to check nan some JS API, returns either int or nan
For the return value we can also convert it from Js.boolean to bool. So that
user can just write Js.Float.isFinite

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bobzhang picture bobzhang  路  4Comments

jordwalke picture jordwalke  路  4Comments

andares picture andares  路  5Comments

paparga picture paparga  路  5Comments

TheSpyder picture TheSpyder  路  5Comments