Flow: Type checking error in with ommited true value in jsx and spread.

Created on 8 Jun 2016  ยท  5Comments  ยท  Source: facebook/flow

This fails


const Foo = ({b, c}: {b: boolean, c: string}) => {
  return <div>{b ? 'true' : 'false'}</div>
}

const Bar = () => {
  const fooProps = {c: 'asdf'}
  return <Foo {...fooProps} b />
}

โฏ flow
props4.js:9
  9:   return <Foo {...fooProps} b />
              ^^^^^^^^^^^^^^^^^^^^^^^ React element `Foo`
  3: const Foo = ({b, c}: {b: boolean, c: string}) => {
                              ^^^^^^^ boolean. This type is incompatible with
  9:   return <Foo {...fooProps} b />
                                 ^

but if you do

const Foo = ({b, c}: {b: boolean, c: string}) => {
  return <div>{b ? 'true' : 'false'}</div>
}

const Bar = () => {
  const fooProps = {c: 'asdf'}
  return <Foo {...fooProps} b={true} />
}

That works. So something with having an implied true value breaks the checker

bug react

Most helpful comment

Here is a minimal example on the "Try" page showing the issue:

image

All 5 comments

Same issue here. probably related to #2623

Here is a minimal example on the "Try" page showing the issue:

image

I think it should be tagged with react and bug tags.

So the original case is now fixed, but @DrewML 's test case still errors.

Looks like that case is now passing as of Flow 0.53:

import * as React from 'react';

const defaultProps = {
  a: false
}

const ABC = function({b}: {b: bool}): React.Element<any> {
  return <div></div>
};

var foo = <ABC {...defaultProps} b />;
Was this page helpful?
0 / 5 - 0 ratings