rescript-compiler
rescript-compiler copied to clipboard
Unpacking first-class module directly in default argument of react component fails
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 />
}
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.