milesj / babel-plugin-typescript-to-proptypes

Generate React PropTypes from TypeScript interfaces or type aliases.
MIT License
367 stars 25 forks source link

Using Mapped Types does not yield any prop type #23

Closed emmenko closed 5 years ago

emmenko commented 5 years ago

Given this usage of Mapped Types (meaning an index signature where index strings can be members of a union of literal strings):

export type Color = "red" | "green";
export type Props {
  colors: {
    [key in Color]: boolean;
  };
}

Then, there are no resulting prop types associated to the prop color.

You can see it from the following failing spec:

Screenshot 2019-09-11 at 11 36 05
emmenko commented 5 years ago

@milesj I'd like to try to fix this, could you point me to the right direction where I should be looking at in the code?

milesj commented 5 years ago

@emmenko You would probably add another if conditional here: https://github.com/milesj/babel-plugin-typescript-to-proptypes/blob/master/src/convertBabelToPropTypes.ts#L24

milesj commented 5 years ago

Will be supported in the next version.