【问题标题】:Adding typescript to an existing react App将打字稿添加到现有的反应应用程序
【发布时间】:2022-12-17 18:04:51
【问题描述】:

我正在尝试将我现有的反应应用程序(几乎是空的)添加/转换为打字稿而不是 JS。所以根据一些教程我添加了一个tsconfig.json文件进入我的项目根目录,内容如下

{
    "compilerOptions": {
      "outDir": "./dist/",
      "noImplicitAny": true,
      "module": "es6",
      "target": "es5",
      "jsx": "react",
      "allowJs": true,
      "moduleResolution": "node",
    }
  }

然后我安装了打字稿

npm install -g typescript

所以我接下来所做的是将我的 index.js 重命名为 index.tsx 和 app.js 以及 app.tsx 并且有一个简单的容器组件,我也将其重命名为 tsx。

但是当我运行应用程序时npm 开始它显示以下错误

我没有得到我错过的或我做错了什么。 React 非常新。

【问题讨论】:

    标签: reactjs typescript


    【解决方案1】:

    反应的安装类型

    npm i -D @types/react @types/react-dom 
    

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 2019-02-16
      • 1970-01-01
      • 2012-01-27
      • 1970-01-01
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多