不能导入react

来源:4-6 初次亮相 - 添加 normalize.css

光aaaaand影

2020-07-30

Could not find a declaration file for module ‘react’. ‘E:/project/learn/shinex/node_modules/react/index.js’ implicitly has an ‘any’ type.
图片描述
老师,这是什么原因呢,难道要跳入react源码中吗

写回答

1回答

张轩

2020-07-31

同学你好 这个原因是比较明显的欧 就是没有 react 的定义文件,我们多次说过,如果使用 typescript,除了源代码,还需要有 @types 文件。你可以使用

npm install  @types/react --save 来安装定义文件。

想问下你是怎样新建的项目,因为 create-react-app 的 ts 模版文件都是有类似的定义文件的。


0
2
张轩
回复
光aaaaand影
你刚开始学 可以删除了整个项目 重新安装一次 使用 npx create-react-app my-app --typescript 这个命令 my-app 是项目名称 随便取名字
2020-07-31
共2条回复

React18+TS高仿AntD从零到一打造组件库

设计,开发,测试,发布再到 CI/CD,从0到1造轮子

2122 学习 · 959 问题

查看课程