reason-react icon indicating copy to clipboard operation
reason-react copied to clipboard

[ppx] type of optional prop not checked correctly in JSX

Open cknitt opened this issue 5 years ago • 1 comments

@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.

cknitt avatar Aug 16 '20 17:08 cknitt

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), ());

cknitt avatar Aug 16 '20 17:08 cknitt