[英]How to fix 'Typescript “Type checking in progress…” taking too long'?
Every time i run the project and change something in a file in my Vuejs front-end app
which is using typescript, the typescript/webpack instantly tells compiled successfully like: DONE Compiled successfully in 635ms
but the type checking will takes too long to tell there is error or not like: No type errors found Version: typescript 3.9.6 Time: 41131ms
and it will use high cpu usage
for this type checking which i think it is harm full for my laptop in a 8h/day developing.每次我运行项目并在使用 typescript 的
Vuejs front-end app
中更改文件中的某些内容时,typescript/webpack 立即告诉编译成功,例如: DONE Compiled successfully in 635ms
但类型检查需要很长时间才能告诉那里是否错误:未No type errors found Version: typescript 3.9.6 Time: 41131ms
,它将使用high cpu usage
进行这种类型检查,我认为这对我的笔记本电脑在 8 小时/天的开发中是有害的。
I tried to set some flags in tsconfig.json
as the docs says https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html :我试图在
tsconfig.json
中设置一些标志,因为文档说https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.ZFC35FDC70D5FC69D269883A23
"incremental": true,
"tsBuildInfoFile": "./buildcache/front-end",
But nothing has been changed, I also tried "watch":true
, but it didn't for either.但什么都没有改变,我也尝试过
"watch":true
,但两者都没有。 So I wonder how should we fix this problem with typescript type checking's problems( taking too long to check and high cpu usage)所以我想知道我们应该如何解决 typescript 类型检查的问题(检查时间过长和 CPU 使用率高)
Update更新
Here is my tsconfig:这是我的 tsconfig:
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"allowJs": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
Update2更新2
You can use this https://github.com/SeyyedKhandon/vuejs-persian-chat-scaffold as a reprex (clone typecheck
branch), and as you can see in this simple app, it takes 2 seconds to type-check, which is not acceptable at all.您可以使用这个
typecheck
://github.com/SeyyedKhandon/vuejs-persian-chat-scaffold作为代表(克隆类型检查分支),正如您在这个简单的应用程序中看到的那样,类型检查需要 2 秒,根本不能接受。 Does it related to vue-composition-api plugin
?它与
vue-composition-api plugin
有关吗?
Update3更新3
I found-out there is a flag named "skipLibCheck": true
in tsconfig.json
, which skips lib type checks which made type-checking 2x faster
.我发现 tsconfig.json 中有一个名为 "
tsconfig.json
"skipLibCheck": true
的标志,它跳过了 lib 类型检查,这使类型检查速度提高了2x faster
。 but still its not good enough.但它仍然不够好。
After spent lots of time on this problem, I decided to upgrade package.json
, at the first step I've upgrade 3 packages including "@vue/composition-api": "^1.0.0-beta.3" -> "^1.0.0-beta.10"
and "sass-loader": "^7.1.0" -> "^9.0.3"
and "typescript": "~3.9.3", -> "~3.9.7"
, and suddenly the typechecking time decreases to 4s
, which was very good promising.在这个问题上花了很多时间后,我决定升级
package.json
,第一步我升级了 3 个包,包括"@vue/composition-api": "^1.0.0-beta.3" -> "^1.0.0-beta.10"
和"sass-loader": "^7.1.0" -> "^9.0.3"
和"typescript": "~3.9.3", -> "~3.9.7"
,然后类型检查时间突然减少到4s
,这是非常有前途的。
So, here is what i did:所以,这就是我所做的:
1.use "skipLibCheck": true
flag in tsconfig.json
, which skips lib type checks which will make type-checking 2x faster. 1.在
tsconfig.json
中使用"skipLibCheck": true
标志,它会跳过 lib 类型检查,这将使类型检查速度提高 2 倍。
->
upgrade your package.json
->
升级您的package.json
you can use yarn upgrade-interactive --latest
but be careful about breaking changes(read the docs to fix you problems, in case of sass-loader upgrading if you have issue read https://stackoverflow.com/a/62844942/12666332 )您可以使用
yarn upgrade-interactive --latest
但要小心破坏性更改(阅读文档以解决您的问题,如果 sass-loader 升级如果您有问题,请阅读https://stackoverflow.com/a/62844942/12666332 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.