Auto import the prop-types package when using PropTypes

Viewed 409

Not sure if this is the right community for it but it's worth a shot for me: I'm using PropTypes from the prop-types npm package. It's perfect for typing your React app but one thing that's really annoying for me is that my vs code editor doesn't recognise the import when i'm using PropTypes. It does make sense to me, since the package is called prop-types and you import it as a default import, most of the times named PropTypes, but i'm wondering if somebody has a nice trick to make this work with auto import in vs code, or any other way so I don't have to import it manually.

So.. when typing:

DiscoverAppsBanner.propTypes = {
  trackingContext: PropTypes
}

I would expect that the import would show up here:

image of propTypes

Anyone out there with a nice idea? :)

2 Answers

From my side, I resolve issue by a crazy trick, I create file with name propTypes.js and I import and export library in this file like this:

import PropTypes from 'prop-types';

export default PropTypes;

By this trick, auto import is work and refer to myfile, and I forget the anyone import.

enter image description here

and the import result import PropTypes from "propTypes";

prop-types is missing the type informations, you can add them with npm i @types/prop-types

Related