简体   繁体   English

打字稿类型检查结果耗时过长

[英]Typescript typecheck results taking excessively long time

I'm converting a relatively new CRA app over to Typescript. 我正在将一个相对较新的CRA应用程序转换为Typescript。 The app is relatively new, though it is setup to be a quite complex app so it has everything from react-router, react-redux, to i18n libraries and various others. 该应用程序相对较新,尽管它设置为非常复杂的应用程序,所以它具有从react-router,react-redux到i18n库等各种内容的所有内容。

Everytime I run 'npm run start', typescript can take anywhere between 20s to several minutes to typecheck each change, even if nothing actually changed. 每次我运行“ npm run start”时,即使没有任何实际更改,打字稿也可能需要20到几分钟的时间才能进行每次检查。

When I run 'tsc --diagnostics', I get the following info: 当我运行'tsc --diagnostics'时,我得到以下信息:

Files:          5677
Lines:        118431
Nodes:           NaN
Identifiers:     NaN
Symbols:      192584
Types:         26014
Memory used: 242096K
I/O read:      8.44s
I/O write:     0.00s
Parse time:   14.28s
Bind time:     0.92s
Check time:    4.63s
Emit time:     0.00s
Total time:   19.84s

I'm wondering why Nodes and Identifiers are showing as NaN . 我想知道为什么节点和标识符显示为NaN I haven't been able to find anyone else having this issue when they run -diagnostics . 在运行-diagnostics时,我找不到其他人遇到此问题。

Can anyone offer any insight into this? 谁能对此提供任何见解? I'm wondering if Typescript is hitting some snags compiling which is resulting in the slow typechecking. 我想知道Typescript是否遇到一些编译障碍,从而导致缓慢的类型检查。

I'm using Typescript v3.4.1 and VS Code v1.3.3 on MacOS High Sierra. 我在MacOS High Sierra上使用Typescript v3.4.1和VS Code v1.3.3。 I've tried deleting/install my node_modules folder to no avail, and tried adding the --incremental flag which is supposed to make Typescript cache buildinfo for future compilations to go faster, but that hasn't done anything either. 我尝试删除/安装我的node_modules文件夹无济于事,并尝试添加--incremental标志,该标志应该使Typescript缓存buildinfo可以使以后的编译更快,但是也没有做任何事情。

my package.json dependencies and devDependencies 我的package.json依赖项和devDependencies

dependencies: 依赖关系:

    "axios": "^0.18.0",
    "browser-locale": "^1.0.3",
    "date-fns": "^1.30.1",
    "i18next": "^15.0.9",
    "i18next-browser-languagedetector": "^3.0.1",
    "prop-types": "^15.6.2",
    "react": "^16.8.4",
    "react-app-polyfill": "^0.2.2",
    "react-dom": "^16.8.4",
    "react-i18next": "^10.6.2",
    "react-loadable": "^5.5.0",
    "react-redux": "^7.0.0-beta.0",
    "react-router": "^5.0.0",
    "react-router-dom": "^5.0.0",
    "react-scripts": "2.1.8",
    "react-transition-group": "^2.5.3",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "source-map-explorer": "^1.6.0",
    "styled-components": "^4.2.0",
    "typeface-roboto": "^0.0.54",
    "typescript": "^3.4.1",
    "use-redux": "^2.2.0"

devDependencies devDependencies


    "@types/material-ui": "^0.21.6",
    "@material-ui/core": "^3.8.2",
    "@material-ui/icons": "^3.0.2",
    "@types/axios": "^0.14.0",
    "@types/date-fns": "^2.6.0",
    "@types/jest": "^24.0.11",
    "@types/node": "^11.13.0",
    "@types/react": "^16.8.12",
    "@types/react-dom": "^16.8.3",
    "@types/react-loadable": "^5.5.1",
    "@types/react-redux": "^7.0.6",
    "@types/react-router": "^4.4.5",
    "@types/redux": "^3.6.0",
    "@types/redux-thunk": "^2.1.0",
    "@types/styled-components": "^4.1.12",
    "@types/react-router-dom": "^4.3.1",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.8.0",
    "jest": "^23.6.0",
    "jest-dom": "^3.0.1",
    "prettier": "1.15.3",
    "react-axe": "^3.1.0",
    "react-testing-library": "^5.4.4",
    "redux-devtools-extension": "^2.13.7",
    "redux-mock-store": "^1.5.3"

There seems to be a performance problem regarding the use of typescript > 3.3.4000 and styled-components . 关于使用typescript > 3.3.4000styled-components似乎存在性能问题。

If you read up on this issue thread , the preliminary solution seems to be to downgrade typescript to 3.3.4000 . 如果您阅读了此问题的线程 ,则初步的解决方案似乎是将typescript降级为3.3.4000 It worked for me in that it brought VS Code up to speed again when checking types while editing. 它对我有用,因为在编辑时检查类型时,它再次使VS Code更快。

In the near future, a fix for this on either styled-components side or typescript is to be expected. 在不久的将来,有望在styled-components方面或typescript方面对此进行修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM