reason-react
reason-react copied to clipboard
[ppx] type of optional prop not checked correctly in JSX
@rickyvetter Following up our discussion on Discord:
Consider the following external declarations for React component A:
module A = {
[@react.component] [@bs.module "a"] external make: (~myProp: bool=?) => React.element = "A";
};
and B:
module B = {
[@react.component] [@bs.module "b"] external make: (~myProp: option(bool)=?) => React.element = "B";
};
For A, myProp has type option(bool).
For B, myProp has type option(option(bool)).
Now the following JSX compiles fine (using bs-platform 8.2.0 and reason-react 0.9.1):
<>
<A />
<B />
<A myProp=true />
<B myProp=true />
</>;
but
<B myProp={Some(true)} />
fails.
I would have expected
<A myProp=true />
<B myProp={Some(true)} />
to be correct and
<B myProp=true />
to fail.
Note that @bs.obj (on which @react.component is based) works correctly:
type t;
[@bs.obj] external makeA: (~myProp: bool=?, unit) => t;
[@bs.obj] external makeB: (~myProp: option(bool)=?, unit) => t;
let a = makeA(~myProp=true, ());
let b = makeB(~myProp=Some(true), ());