javascript - React Typescript - import @types/react 和 import react 有什么区别
问题描述
我是 React 的初学者(即使我已经做了一些 ReactJs),我今天正在尝试使用TypeScript (instead of pure Javascript)
.
但是,在运行 npm start 时,我发现了一个我理解的问题,但我不明白为什么它是一个问题。
假设我们有这段代码(main.tsx):
import * as React from 'react';
你能清楚地向我解释一下有什么区别吗
import * as React from '@types/react';
在我的 package.json 中"@types/react": "^16.9.2"
,我有也没有react
,所以问题是找不到包的逻辑。但是,这两个进口之间有什么区别?
另外,我什至不能导入@types/react
,我只能安装它
谢谢 !
解决方案
带有@types
前缀的是类型声明包,更多信息在这里。
推荐阅读
- python - 在python中的tkinter.ttk中制作图像精确中心
- python - 如何在不使用 `self.parent.parent. ...`?
- asp.net-core - 如何在 Asp.net 核心的 appsettings.json 中定义角色身份资源
- c# - 线程是否与 await 语句一起使用?
- java - 单元测试中的模拟不起作用。选择进入数据库现在正在工作
- vue.js - 为新表单提交添加错误检查:Vue+Vuetify
- javascript - 打字稿参数不能在提取中使用任何?
- reactjs - 来自 Stack.Screen 的 React Native Navigation Access Navigation
- javascript - 使用 UseEffect 代替 componentDidMount 和 componentDidUpdate 时遇到问题
- javascript - 如何在 Vuejs 中的 Promise 中发出和事件