layershifter / babel-plugin-transform-react-handled-props

Generates handledProps from defaultProps and propTypes during the build :sparkles:
MIT License
19 stars 4 forks source link

feat(plugin): add support for Flow #32

Closed simonguo closed 5 years ago

simonguo commented 6 years ago

in

// @flow

import * as React from 'react';
import PropTypes from 'prop-types';

type Props = {
  name?: string,
  _text?: string,
  'aria-describedby'?: string,
  children?: React.Node
}

class Baz extends React.Component<Props> {

  render() {
    return <div {...this.props} />;
  }
}

export default Baz;

out:

// @flow

import * as React from 'react';
import PropTypes from 'prop-types';

type Props = {
  name?: string;
  _text?: string;
  'aria-describedby'?: string;
  children?: React.Node;
};

class Baz extends React.Component<Props> {

  render() {
    return <div {...this.props} />;
  }
  static handledProps = ['_text', 'aria-describedby', 'children', 'name'];
}

export default Baz;
layershifter commented 6 years ago

@simonguo Thanks again for your PR, it's awesome work 👍 I've made a little styling cleanup there and added a broken test.

flow-non-concerning shows a problem in current implementation. I see that we need:

As I remember, we can use for resolving type identifier.


Will be awesome to hear your feedback

P.S. Sorry for delay, I have too much work now 😢