【发布时间】: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