问题描述:

我在react中用typescript时,定义一个Home组件,然后在组件里用setState时会有这样一个报错:(如图)Property 'setState' does not exist on type 'Home'

react中使用typescript时,error: Property 'setState' does not exist on type 'Home'react中使用typescript时,error: Property 'setState' does not exist on type 'Home'

 

 

 

分析解决:

  报错说我的Home组件上不存在setState属性,但是我把文件的后缀名从‘.tsx’改成‘.jsx’就不报这个错了,推断是typescript的类型检查报的这个错,识别不了react组件就不认为这个class函数上有setState属性。安装一下react、react-dom的类型定义就解决啦

npm install --save-dev  "@types/react"  "@types/react-dom"

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-07-22
  • 2022-12-23
猜你喜欢
  • 2021-12-31
  • 2021-08-11
  • 2021-09-08
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
相关资源
相似解决方案