nestjs / axios

Axios module for Nest framework (node.js) 🗂

Home Page:https://docs.nestjs.com/techniques/http-module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typescript error in dist/http.service.d.ts in "@nestjs/axios": "^2.0.0"

vladimirverh opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When run nest build with "@nestjs/axios": "^2.0.0" in package.json, I get this Typescript error:

backend2>nest build
node_modules/@nestjs/axios/dist/http.service.d.ts:14:105 - error TS2707: Generic type 'AxiosResponse<T>' requires between 0 and 1 type arguments.

14     protected makeObservable<T>(axios: (...args: any[]) => AxiosPromise<T>, ...args: any[]): Observable<AxiosResponse<T, any>>;
                                                                                                           ~~~~~~~~~~~~~~~~~~~~~

Found 1 error(s).

If I'll manually change type in node_modules/@nestjs/axios/dist/http.service.d.ts
from
protected makeObservable<T>(axios: (...args: any[]) => AxiosPromise<T>, ...args: any[]): Observable<AxiosResponse<T, any>>;
to
protected makeObservable<T>(axios: (...args: any[]) => AxiosPromise<T>, ...args: any[]): Observable<AxiosResponse<T>>;
nest build will run without errors.

Looks like a bug, because we expect to receive Observable with type.

Minimum reproduction code

https://github.com/vladimirverh/repro-nestjs-2.0.0-TS-issue/blob/main/package.json

Steps to reproduce

  1. yarn install
yarn install v1.22.10
[1/5] Validating package.json...
[2/5] Resolving packages...
success Already up-to-date.
  1. nest build
  2. See error
node_modules/@nestjs/axios/dist/http.service.d.ts:14:105 - error TS2707: Generic type 'AxiosResponse<T>' requires between 0 and 1 type arguments.

14     protected makeObservable<T>(axios: (...args: any[]) => AxiosPromise<T>, ...args: any[]): Observable<AxiosResponse<T, any>>;
                                                                                                           ~~~~~~~~~~~~~~~~~~~~~

Found 1 error(s).

Expected behavior

nest build should run without Typescript errors.

Package version

9.3.6

NestJS version

9.3.6

Node.js version

16.13.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

package.json (in case GitHub url not working):
{
"name": "backend",
"version": "1.0.0",
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"start": "nest start",
"start:dev": "nest start --watch",
"test": "mocha --timeout 90000 --exit"
},
"dependencies": {
"@nestjs/axios": "^2.0.0",
"@nestjs/common": "^9.3.6",
"@nestjs/config": "^2.3.0",
"@nestjs/core": "^9.3.6",
"@nestjs/platform-express": "^9.3.6",
"@nestjs/schedule": "^2.2.0",
"@nestjs/typeorm": "^9.0.1",
"bcrypt": "^5.0.1",
"cache-manager": "^3.4.4",
"cache-manager-redis-store": "^2.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cookie-parser": "^1.4.5",
"lodash": "^4.17.21",
"pg": "^8.9.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.8.0",
"typeorm": "^0.3.11",
"winston": "^3.7.2",
"yarn": "^1.22.10"
},
"devDependencies": {
"@nestjs/cli": "^9.2.0",
"@nestjs/schematics": "^9.0.4",
"@nestjs/testing": "^9.3.2",
"@types/bcrypt": "^5.0.0",
"@types/cache-manager": "^3.4.2",
"@types/chai": "^4.2.21",
"@types/chai-as-promised": "^7.1.4",
"@types/cron": "^1.7.3",
"@types/express": "^4.17.17",
"@types/body-parser": "^1.19.2",
"@types/faker": "^5.5.8",
"@types/lodash": "^4.14.171",
"@types/mocha": "^9.0.0",
"@types/multer": "^1.4.7",
"@types/newrelic": "^7.0.3",
"@types/node": "^16.18.12",
"@types/sinon": "^10.0.2",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",
"faker": "^5.5.3",
"mocha": "^9.0.3",
"nodemon": "^2.0.20",
"prettier": "^2.2.1",
"sinon": "^11.1.2",
"ts-loader": "^8.0.18",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typeorm-fixtures-cli": "^1.9.1",
"typescript": "^4.9.5"
}
}

actually, I just notice that, since now axios is a peer dependecy of @nestjs/axios, you must respect the semver range below:

axios/package.json

Lines 47 to 49 in 02a94cd

"peerDependencies": {
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0",
"axios": "^1.3.1",

so make sure you got axios installed in your side

Ohh my, I don't have axios in dependencies at all. But let me check deeply and add some repro example.

actually, I just notice that, since now axios is a peer dependecy of @nestjs/axios, you must respect the semver range below:

axios/package.json

Lines 47 to 49 in 02a94cd

"peerDependencies": {
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0",
"axios": "^1.3.1",

so make sure you got axios installed in your side

This one helped - with adding direct dependency
"axios": "^1.3.1",
in dependencies nest build just worked. Many thanks for the help! ❤️ 🤝
Just for reference, repo with updated NestJS dependencies and @nestjs/axios is here:
https://github.com/vladimirverh/repro-nestjs-2.0.0-TS-issue-2
I'll try to use same repo in future while doing any upgrade.

Thanks for you cool project and everyday job! Love that, you are the best!!! 💪 🚀

Related one: #663