gpt4 book ai didi

reactjs - typescript 类型检查结果花费的时间过长

转载 作者:行者123 更新时间:2023-12-04 13:19:29 25 4
gpt4 key购买 nike

我正在将一个相对较新的 CRA 应用程序转换为 Typescript。该应用程序相对较新,尽管它被设置为一个非常复杂的应用程序,因此它具有从 react-router、react-redux 到 i18n 库和各种其他应用程序的所有内容。

每次我运行“npm run start”时,typescript 可能需要 20 秒到几分钟的时间来对每个更改进行类型检查,即使实际上没有任何更改。

当我运行“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

我想知道为什么节点和标识符显示为 NaN。我没能找到其他人在运行 -diagnostics 时遇到此问题。

任何人都可以对此提供任何见解吗?我想知道 Typescript 是否遇到了一些编译障碍,导致类型检查缓慢。

我在 MacOS High Sierra 上使用 Typescript v3.4.1 和 VS Code v1.3.3。我尝试删除/安装我的 node_modules 文件夹无济于事,并尝试添加 --incremental 标志,这应该使 Typescript 缓存构建信息以便将来的编译速度更快,但这还没有完成任何东西。

我的 package.json 依赖和 devDependencies

依赖关系:

    "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"

开发依赖


"@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"

最佳答案

typescript > 3.3.4000styled-components 的使用似乎存在性能问题。

如果您阅读此 issue thread ,初步的解决方案似乎是将typescript降级为3.3.4000。它对我有用,因为它在编辑时检查类型时再次加快了 VS Code 的速度。

在不久的将来,预计会在 styled-components 端或 typescript 上对此进行修复。

关于reactjs - typescript 类型检查结果花费的时间过长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55624799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com