开发者问题收集

我有一个 Typescript 问题,已经问过几个人了,很多人在升级版本中得到了解决方案。但对我来说不起作用。

2021-10-20
677

D:/.../../node_modules/@reduxjs/toolkit/dist/configureStore.d.ts D:/.../.../node_modules/@reduxjs/toolkit/dist/configureStore.d.ts(1,13) 中的 TypeScript 错误: 预期为 '='。TS1005

1 | import type { Reducer, ReducersMapObject, Middleware, Action, AnyAction, StoreEnhancer, Store, Dispatch, PreloadedState, CombinedState } from 'redux'; | ^ 2 | import type { EnhancerOptions as DevToolsOptions } from './devtoolsExtension'; 3 | import type { ThunkMiddlewareFor, CurriedGetDefaultMiddleware } from './getDefaultMiddleware'; 4 | import type { DispatchForMiddlewares, NoInfer } from './tsHelpers';

我尝试过大多数解决方案,例如升级 typescript 4.4.4 和 node 14

这是 Package.json,如果需要,我可以分享更多信息

 {
  "name": "project9a-shopping-cart-with-redux",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@reduxjs/toolkit": "^1.4.0",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "@types/classnames": "^2.2.10",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "@types/react-redux": "^7.1.9",
    "@wellyshen/use-web-animations": "^0.5.5",
    "classnames": "^2.2.6",
    "history": "^5.0.0",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-icons": "^3.11.0",
    "react-redux": "^7.2.1",
    "react-router-dom": "^6.0.0-beta.0",
    "react-scripts": "3.4.3",
    "yarn": "^1.22.17"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "typescript": "^4.4.4"
  }
}
1个回答

H3AR7B3A7 是的,你猜对了,我从 github 下载了某人的代码并运行 npm install,以便特定的软件和依赖项自动安装到他们身上,但不知何故在我的电脑上 typescript 4.4.4 是全局安装的,而 github 上的代码是 3.7.7,但在 npm 安装之后,我尝试再次手动更新 package.json 4.4.4 并再次运行 npm install,即使它用 tsc -v 显示这个文件夹有 4.4.4,但我希望内部系统混淆了。
所以我在另一个文件夹中尝试了同样的过程,但这次在运行 npm install 之前,我将 3.7.7 更改为 4.4.4 并运行 npm install,之后工作正常

abbott2964
2021-10-27