rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Clean up/optimize @return(undefined_to_opt) etc.

Open cknitt opened this issue 7 months ago • 1 comments

We currently have the following special directives for external function definitions:

@return(nullable)
external someFunc1: unit => option<string> = "someFunc"

@return(null_undefined_to_opt)
external someFunc2: unit => option<string> = "someFunc"

@return(undefined_to_opt)
external someFunc3: unit => option<string> = "someFunc"

@return(null_to_opt)
external someFunc4: unit => option<string> = "someFunc"
  • 1 and 2 are actually the same.
  • For 2, 3, and 4, the naming is unidiomatic (no camelCase, ...).
  • 3 is probably not needed anymore as one could just define the external to return an option?
  • Only 1 is actually documented.

cknitt avatar May 05 '25 16:05 cknitt

~~Actually @return(undefined_to_opt) is useful to ensure nested options work correctly, see also the discussion in #7054 and #7430.~~

It is currently used in Js.Array(2) for example.

cknitt avatar May 06 '25 08:05 cknitt

Removed @return(undefined_to_opt) in #7462.

cknitt avatar Aug 06 '25 22:08 cknitt