How to write interface for function with optional lebeled parameter

I have a function with optional lebeled parameter, for example:

let foo = (~name=1, value) => value + name

And in the interface file:

let foo: (~?name: int, int) => int

But the interface file is always get reformated to

let foo: (~name: int, int) => int

And the compiler will complain:

Values do not match:
         let foo: (~?name: int, int) => int
       is not included in
         let foo: (~name: int, int) => int

So is there any other way to write interface for these functions?

The error message is weird. ~?name is not valid syntax, but it looks like the parser is just ignoring the ?. Either way, this is the correct syntax:

let foo: (~name: int=?, int) => int

Mentioned in the docs here.

2 Likes

It works now. Thank you.
Btw the rescript dump command for the implementation will output the interface without “=?” part, and it will not compile.

I just reported this here :slightly_smiling_face:

2 Likes