24

I am trying to use https://github.com/facebook/prop-types

So I have also installed the @types/prop-types for it. https://www.npmjs.com/package/@types/prop-types

But I guess this error. [ts] Module '"/node_modules/@types/prop-types/index"' has no default export.

What I am trying to accomplish is what is being done in the withRouter documentation. https://reacttraining.com/react-router/web/api/withRouter

For example you see in their JavaScript the use of PropTypes:

import React from 'react'
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'

// A simple component that shows the pathname of the current location
class ShowTheLocation extends React.Component {
  static propTypes = {
    match: PropTypes.object.isRequired,
    location: PropTypes.object.isRequired,
    history: PropTypes.object.isRequired
  }

  render() {
    const { match, location, history } = this.props

    return (
      <div>You are now at {location.pathname}</div>
    )
  }
}

// Create a new component that is "connected" (to borrow redux
// terminology) to the router.
const ShowTheLocationWithRouter = withRouter(ShowTheLocation)

Any help on this is appreciated!

Jordan McDonald
  • 1,101
  • 3
  • 14
  • 24

1 Answers1

38

You need to modify your import statement like so

import * as PropTypes from 'prop-types'

What this says is create an object PropTypes, and import all the exports in the prop-types module into the PropTypes object.

sylvanaar
  • 8,096
  • 37
  • 59