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

Unpacking first-class module directly in default argument of react component fails

Open glennsl opened this issue 3 months ago • 1 comments

Given these definitions:

module M = {
  @react.component
  let make = () => React.null
}
module type S = module type of M

Trying to unpack a first-class module in the argument of a react component:

@react.component
let make = (~component as module(C: S)=module(M)) => <M />

fails with the error

This pattern matches values of type module(S)
  but a pattern was expected which matches values of type option<'a>

The workaround is to unpack the module in the function body instead:

@react.component
let make = (~component=module(M: S)) => {
  module C = unpack(component)
  <C />
}

glennsl avatar Sep 22 '25 12:09 glennsl

This is not new in v12, btw, it goes back to v11. It doesn't work entirely in v10 either, but it seems to be a name mangling error instead of a type error then.

glennsl avatar Sep 22 '25 12:09 glennsl