简体   繁体   English

打字稿和@ types / react错误

[英]typescript and @types/react errors

I'm still learning to use typescript with react. 我仍在学习使用带有响应的打字稿。 Due to how slow react-scripts-ts was, I was turned off from it. 由于react-scripts-ts的速度很慢,所以我被关闭了。 I've tried the new typescript setup with babel 7 ( react-webpack-typescript-babel ) and its exceedingly fast. 我已经尝试了使用babel 7( react-webpack-typescript-babel )的新打字稿设置,并且安装速度非常快。 However there are some basic errors that I can't resolve. 但是,有些基本错误我无法解决。

Even though the project runs, in vscode I get the following errors: 即使项目正在运行,在vscode中我仍然遇到以下错误:

  • [ts] Module ...@types/react... has no exported member 'Component' [ts]模块... @ types / react ...没有导出的成员'Component'
  • [ts] Property 'setState' does not exist on type 'Counter' [ts]类型“ Counter”上不存在属性“ setState”
  • [ts] Module ...@types/react... has no exported member 'SFC' [ts]模块... @ types / react ...没有导出的成员'SFC'
  • [ts] Unknown compiler option 'esModuleInterop' [ts]未知的编译器选项'esModuleInterop'
  • and more... 和更多...

I'm assuming this is a @types/react and typescript issue. 我假设这是一个@ types / react和typescript问题。

  1. Is @types/react not being updated? @ types / react是否未更新?
  2. How I can get the other properties to show up? 如何显示其他属性?
  3. I also don't understand when to download from @types vs use the @types found in some packages other than reading the package description. 我还不明白何时从@types下载与使用某些软件包中的@types相比,除了阅读软件包说明外。

Based on @lleon input, an old typescript version was the cause of my headache. 根据@lleon输入,旧的打字稿版本使我头痛。 I removed it npm un -g typescript , added vscode user setting "typescript.tsdk": "node_modules\\\\typescript\\\\lib" and restarted vscode. 我删除了npm un -g typescript typescript,添加了vscode用户设置"typescript.tsdk": "node_modules\\\\typescript\\\\lib"然后重新启动了vscode。 Works well so far. 到目前为止效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM