ウェブサイト検索

node.js - TSを4.6.4から4.7.4に更新した後のaxios/index.d.tsでの型エラー


タイトルの通り、今夜いくつかの依存関係を更新したところ、npx tsc コマンドを使用するとエラーが発生するようになりました。どうやら TypeScript に何か変更があったようで、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 => 4.7.4
  • @types/node 17.0.35 => 18.0.0
  • ts-node 10.8.0 => 10.8.1

私の 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"
  }
}

そして私の tsconfig.json

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

編集: さらにテストしたところ、ts-node を使うとサーバーは正常に起動します。ただ、npx tsc ではトランスパイルされません。