[英]How to fix 'Typescript “Type checking in progress…” taking too long'?
每次我運行項目並在使用 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 小時/天的開發中是有害的。
我試圖在tsconfig.json
中設置一些標志,因為文檔說https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.ZFC35FDC70D5FC69D269883A23
"incremental": true,
"tsBuildInfoFile": "./buildcache/front-end",
但什么都沒有改變,我也嘗試過"watch":true
,但兩者都沒有。 所以我想知道我們應該如何解決 typescript 類型檢查的問題(檢查時間過長和 CPU 使用率高)
更新
這是我的 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"
]
}
更新2
您可以使用這個typecheck
://github.com/SeyyedKhandon/vuejs-persian-chat-scaffold作為代表(克隆類型檢查分支),正如您在這個簡單的應用程序中看到的那樣,類型檢查需要 2 秒,根本不能接受。 它與vue-composition-api plugin
有關嗎?
更新3
我發現 tsconfig.json 中有一個名為 " tsconfig.json
"skipLibCheck": true
的標志,它跳過了 lib 類型檢查,這使類型檢查速度提高了2x faster
。 但它仍然不夠好。
在這個問題上花了很多時間后,我決定升級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
,這是非常有前途的。
所以,這就是我所做的:
1.在tsconfig.json
中使用"skipLibCheck": true
標志,它會跳過 lib 類型檢查,這將使類型檢查速度提高 2 倍。
->
升級您的package.json
您可以使用yarn upgrade-interactive --latest
但要小心破壞性更改(閱讀文檔以解決您的問題,如果 sass-loader 升級如果您有問題,請閱讀https://stackoverflow.com/a/62844942/12666332 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.