@ types / prop-types / index has no default export

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

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

But I think this is a mistake. [ts] The module '"/ node_modules / @ types / prop-types / index" "does not have a default export.

I'm trying to do what the withRouter documentation does. https://reacttraining.com/react-router/web/api/withRouter

For example, you can 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!

+7


source to share


1 answer


You must change your import statement as follows

import * as PropTypes from 'prop-types'

      



This says create an object PropTypes

and import all exports from the module prop-types

to the object PropTypes

.

+17


source







All Articles