从TS 4.6.4到4.7.4更新后,Axios/index.d.ts中的键入错误

发布于 2025-02-10 23:41:32 字数 2041 浏览 1 评论 0原文

正如标题所说,今晚我更新了一些依赖关系,现在使用NPX TSC命令时会出现错误。看起来像是在打字稿中发生了变化,Axios需要相应地进行更新,但我不确定。有人可以让我知道Axios(或其他内容)是否不再兼容,或者我只需要在Tsconfig中更新某些内容?

错误是

PS C:\Projects\ModsList\express-app> npx tsc
node_modules/axios/index.d.ts:156:3 - error TS2416: Property 'status' in type 'AxiosError<T, D>' is not assignable to the same property in base type 'Error'.
  Type 'string | undefined' is not assignable to type 'number | undefined'.
    Type 'string' is not assignable to type 'number'.

156   status?: string;
      ~~~~~~


Found 1 error in node_modules/axios/index.d.ts:156

我更新的依赖项是:

  • typescript 4.6.4 =&gt; 4.7.4
  • @types/node 17.0.35 =&gt; 18.0.0
  • TS节点10.8.0 =&gt; 10.8.1

我的软件包。JSON

  "name": "express-app",
  "version": "0.4.0-dev",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "ts-node-dev --respawn --exit-child --watch src ./src/index.ts",
    "start": "ts-node ./src/index.ts",
    "startjs": "node ./dist/index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@prisma/client": "^3.15.2",
    "@quixo3/prisma-session-store": "^3.1.7",
    "ajv": "^8.11.0",
    "axios": "^0.27.2",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "express": "^4.18.1",
    "express-session": "^1.17.2"
  },
  "devDependencies": {
    "@types/cookie-parser": "^1.4.3",
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.13",
    "@types/express-session": "^1.17.4",
    "@types/node": "^18.0.0",
    "prisma": "^3.15.2",
    "ts-node": "^10.8.1",
    "ts-node-dev": "^2.0.0",
    "typescript": "^4.7.4"
  }
}

和我的TSCONFIG.JSON

    "compilerOptions": {
      "sourceMap": false,
      "outDir": "dist",
      "rootDir": "src",
      "strict": true,
      "lib": ["ES2021"],
      "esModuleInterop": true,
      "target": "ES2021",
      "moduleResolution": "node",
    }
}

编辑:进一步测试后,如果使用TS节点,服务器启动正常。它只是不会用NPX TSC转移。

As the title says, I updated a few dependencies tonight, and now I get an error when I use the npx tsc command. It looks like something changed in Typescript and Axios will need to update accordingly, but I'm not totally sure. Can someone please let me know if Axios (or something else) is no longer compatible, or if I simply need to update something in my tsconfig?

The error is

PS C:\Projects\ModsList\express-app> npx tsc
node_modules/axios/index.d.ts:156:3 - error TS2416: Property 'status' in type 'AxiosError<T, D>' is not assignable to the same property in base type 'Error'.
  Type 'string | undefined' is not assignable to type 'number | undefined'.
    Type 'string' is not assignable to type 'number'.

156   status?: string;
      ~~~~~~


Found 1 error in node_modules/axios/index.d.ts:156

The dependencies that I updated are:

  • typescript 4.6.4 => 4.7.4
  • @types/node 17.0.35 => 18.0.0
  • ts-node 10.8.0 => 10.8.1

My package.json

  "name": "express-app",
  "version": "0.4.0-dev",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "ts-node-dev --respawn --exit-child --watch src ./src/index.ts",
    "start": "ts-node ./src/index.ts",
    "startjs": "node ./dist/index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@prisma/client": "^3.15.2",
    "@quixo3/prisma-session-store": "^3.1.7",
    "ajv": "^8.11.0",
    "axios": "^0.27.2",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "express": "^4.18.1",
    "express-session": "^1.17.2"
  },
  "devDependencies": {
    "@types/cookie-parser": "^1.4.3",
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.13",
    "@types/express-session": "^1.17.4",
    "@types/node": "^18.0.0",
    "prisma": "^3.15.2",
    "ts-node": "^10.8.1",
    "ts-node-dev": "^2.0.0",
    "typescript": "^4.7.4"
  }
}

and my tsconfig.json

    "compilerOptions": {
      "sourceMap": false,
      "outDir": "dist",
      "rootDir": "src",
      "strict": true,
      "lib": ["ES2021"],
      "esModuleInterop": true,
      "target": "ES2021",
      "moduleResolution": "node",
    }
}

Edit: After further testing, the server starts up fine if I use ts-node. It just won't transpile with npx tsc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文