milesj / babel-plugin-typescript-to-proptypes

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

Making it work with `create-react-app --template typscript` #66

Open Sourav12061999 opened 1 year ago

Sourav12061999 commented 1 year ago

I want some help on how to set this up with the `create-react-app --template typescript, I am not sure I am doing something wrong or it's some issue from the package itself

maurer2 commented 1 year ago

Hello, I believe the following should work:

  1. Eject CRA (to gain access to babel config)
  2. Install babel-plugin-typescript-to-proptypes
  3. Create a babel.config.js file, that contains the babel settings from the Readme.md file.
  4. Remove babel settings from package.json
  5. Change process.env.BABEL_ENV to "development" in scripts/build.js, otherwise the proptypes are removed in prod mode
  6. Add import React from "react"; to each component, even if it is not needed anymore when using the new JSX transform. Otherwise the proptypes won't be exported (see https://github.com/milesj/babel-plugin-typescript-to-proptypes/issues/64)
  7. Runnpm run build. Proptypes should still be in the compiled files in build/static/js/*.js