2021年3月22日星期一

Typescript, ESlint and node-fetch? (response.json() issue)

I have an apollo-server-express backend with the following code to fetch an external API with node-fetch: (See in TypeScript Playground)

The TypeScript compiles and works fine, but ESlint keeps throwing the error 'Unsafe assignment of an any value.' no matter what I do with the line const credentials: Promise<IGDBCredentials> = await response.json();

Any idea of how I am meant to safely type that response or where might the issue be?

Cheers =)

My .eslintrc file:

{    "extends": [      "eslint:recommended",      "plugin:@typescript-eslint/recommended",      "plugin:@typescript-eslint/recommended-requiring-type-checking"    ],    "plugins": ["@typescript-eslint"],    "env": {      "browser": true,      "es6": true,      "node": true,      "jest": true    },    "rules": {      "@typescript-eslint/semi": ["error"],      "@typescript-eslint/explicit-function-return-type": "off",      "@typescript-eslint/explicit-module-boundary-types": "off",      "@typescript-eslint/restrict-template-expressions": "off",      "@typescript-eslint/restrict-plus-operands": "off",      "@typescript-eslint/no-unsafe-member-access": "off",      "@typescript-eslint/no-unused-vars": [        "error",        { "argsIgnorePattern": "^_" }      ],      "no-case-declarations": "off"    },    "parser": "@typescript-eslint/parser",    "parserOptions": {      "project": "./tsconfig.json"    },    "root": true  }  

Aparently node-fetch versions older than 3.0.0 require the additional installation of @types/node-fetch, but doing that has still not solved the problem.

https://stackoverflow.com/questions/66757147/typescript-eslint-and-node-fetch-response-json-issue March 23, 2021 at 12:06PM

没有评论:

发表评论