milesj / babel-plugin-typescript-to-proptypes

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

Rename import #60

Open jamesmsk opened 2 years ago

jamesmsk commented 2 years ago

I'm using this package to have a react js copy of my react typescript components. Is it possible to control the import name?

currently its

import _pt from 'prop-types';

I would like to have control of name instead of _pt

milesj commented 2 years ago

@jamesmsk If an import already exists, the plugin will use that name, otherwise no.

Curious why you need this? This is an abstraction that isn't used directly.

jamesmsk commented 2 years ago

@jamesmsk If an import already exists, the plugin will use that name, otherwise no.

Curious why you need this? This is an abstraction that isn't used directly.

Our mono repo's react components are all written in TypeScript and we needed to compensate for contributors who do not work with TypeScript. Readability and speed of development are the reasons for this. When I transpile from React TS to JS, I want the contributors to have a js version of the source file that they can comprehend quickly. So, in this example, I wanted babel to punch out js files with import PropTypes from 'prop-types to keep with the syntax they are historically using.