Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs @类型/道具类型/索引没有默认导出_Reactjs_Typescript_React Router V4 - Fatal编程技术网

Reactjs @类型/道具类型/索引没有默认导出

Reactjs @类型/道具类型/索引没有默认导出,reactjs,typescript,react-router-v4,Reactjs,Typescript,React Router V4,我正在尝试使用 所以我也为它安装了@types/prop类型 但我猜这是个错误。 [ts]模块“/node_modules/@types/prop types/index”没有默认导出 我试图完成的是withRouter文档中所做的工作。 例如,您可以在JavaScript中看到PropType的使用: import React from 'react' import PropTypes from 'prop-types' import { withRouter } from 'react-r

我正在尝试使用

所以我也为它安装了@types/prop类型

但我猜这是个错误。 [ts]模块“/node_modules/@types/prop types/index”没有默认导出

我试图完成的是withRouter文档中所做的工作。

例如,您可以在JavaScript中看到PropType的使用:

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)
从“React”导入React
从“道具类型”导入道具类型
从“react router”导入{withRouter}
//显示当前位置路径名的简单组件
类ShowTheLocation扩展了React.Component{
静态类型={
匹配:PropTypes.object.isRequired,
位置:PropTypes.object.isRequired,
历史记录:PropTypes.object.isRequired
}
render(){
const{match,location,history}=this.props
返回(
您现在位于{location.pathname}
)
}
}
//创建一个“已连接”的新组件(借用redux
//术语)到路由器。
const ShowTheLocationWithRouter=withRouter(ShowTheLocation)

在此感谢您的帮助

您需要像这样修改导入语句

import * as PropTypes from 'prop-types'

这意味着创建一个对象
PropTypes
,并将
PropTypes
模块中的所有导出导入到
PropTypes
对象中。

我对所有
import
语句都做了同样的操作