@types/prop-types/index 没有默认导出
@types/prop-types/index has no default export
我正在尝试使用 https://github.com/facebook/prop-types
所以我也为它安装了@types/prop-types。 https://www.npmjs.com/package/@types/prop-types
但是我猜这个错误。
[ts] 模块 '"/node_modules/@types/prop-types/index"' 没有默认导出。
我想要完成的是 withRouter 文档中正在做的事情。
https://reacttraining.com/react-router/web/api/withRouter
例如你在他们的 JavaScript 中看到 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)
如有任何帮助,我们将不胜感激!
您需要像这样修改导入语句
import * as PropTypes from 'prop-types'
这里说的是创建一个对象 PropTypes
,并将 prop-types
模块中的所有导出导入到 PropTypes
对象中。
我正在尝试使用 https://github.com/facebook/prop-types
所以我也为它安装了@types/prop-types。 https://www.npmjs.com/package/@types/prop-types
但是我猜这个错误。 [ts] 模块 '"/node_modules/@types/prop-types/index"' 没有默认导出。
我想要完成的是 withRouter 文档中正在做的事情。 https://reacttraining.com/react-router/web/api/withRouter
例如你在他们的 JavaScript 中看到 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)
如有任何帮助,我们将不胜感激!
您需要像这样修改导入语句
import * as PropTypes from 'prop-types'
这里说的是创建一个对象 PropTypes
,并将 prop-types
模块中的所有导出导入到 PropTypes
对象中。