babel-plugin-react-flow-props-to-prop-types icon indicating copy to clipboard operation
babel-plugin-react-flow-props-to-prop-types copied to clipboard

Add `React$Element` faux-generic

Open sdougbrown opened this issue 8 years ago • 1 comments

Using React$Element<*> provides additional safety, and it'd be nice if this plugin would support it rather than having to any-stub for children and go backwards.

The only thing that's holding me up is adding the test - I seem to be getting an undefined result. Not sure if that's because the fbjs lib with the React$Element definition isn't included?

 FAIL  src/__tests__/classes.test.js
  ● react-flow-props-to-prop-types › 24. React$Element

    TypeError: unknown: Property object of MemberExpression expected node to be of a type ["Expression"] but instead got undefined

The test should probably look something like...

    {
      title: 'React$Element',
      code: `
        class Foo extends React.Component {
          props: {
            a: React$Element<*>
          };
        }
      `,
      output: `
        import _PropTypes from "prop-types";
        class Foo extends React.Component {
          props: {
            a: React$Element<*>
          };
          static propTypes = {
            a: _PropTypes.element.isRequired
          };
        }
      `,
    },

Thanks for your work on this.

sdougbrown avatar Jun 12 '17 21:06 sdougbrown

In general it appears this plugin, like others, has no awareness of flow's built-in libdefs or locally installed libdefs (e.g. flow-typed). @thejameskyle is there a plan for this?

rosskevin avatar Jun 12 '17 23:06 rosskevin