【问题标题】:TypeScript won't change error (terminal output) even when problem has been fixed in React application即使问题已在 React 应用程序中修复,TypeScript 也不会更改错误(终端输出)
【发布时间】:2020-08-08 23:39:35
【问题描述】:

我是 TypeScript 的新手,正面临这个烦人的问题。终端(或整个项目)不会像带有 JS 的常规 React 应用程序那样自动刷新。通常,当我进行更改和修复 linter 指出的错误时,开发服务器会自动刷新并显示已编译的产品或后续错误。

在从 JS 迁移到 TS 的项目和以 TS 开始的项目中都会发生这种情况。

tsconfig.json 用于使用 create-react-app 和 TS 引导的项目

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  },
  "include": [
    "src"
  ]
}

在我使用 TS 启动的一个项目中,我是这样安装的:

npx create-react-app my-project --template typescript

在我尝试迁移的另一个项目中,这是我安装必要东西的方式:

npm install -D typescript
npx tsc -init 
npm install -D @types/react @types/react-dom @types/reach__router

【问题讨论】:

    标签: reactjs typescript visual-studio-code


    【解决方案1】:

    我可以观察到同样的事情。不是真正的修复,而是快速的解决方法:在某处插入一个空格(例如在空行中)并保存文件。错误应该已经消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-11
      • 1970-01-01
      • 2021-04-23
      • 2015-05-01
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多