Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript issues with axios >= 0.27 #2045

Closed
2 of 4 tasks
Toilal opened this issue Sep 23, 2022 · 1 comment
Closed
2 of 4 tasks

Typescript issues with axios >= 0.27 #2045

Toilal opened this issue Sep 23, 2022 · 1 comment

Comments

@Toilal
Copy link

Toilal commented Sep 23, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Axios >= 0.27 type definitions are not compatible with those declared in https://github.com/nestjs/terminus/blob/master/lib/health-indicator/http/axios.interfaces.ts.

method property is now Method | string in axios, causing this kind of compilation error.

Type 'AxiosRequestConfig<any>' is not assignable to type 'AxiosRequestConfig'.
  Types of property 'method' are incompatible.
    Type 'string | undefined' is not assignable to type 'Method | undefined'.
      Type 'string' is not assignable to type 'Method | undefined'.

Minimum reproduction code

import { Controller, Get, Param } from '@nestjs/common'
import { HealthCheck, HealthCheckService, HealthIndicatorFunction, HttpHealthIndicator } from '@nestjs/terminus'
import { NotFoundError } from 'nest-common.carbon-saver'
import type { AxiosRequestConfig } from 'axios'

@Controller('health')
export class HealthController {
  checks: Map<string, HealthIndicatorFunction> = new Map<string, HealthIndicatorFunction>()

  constructor (private health: HealthCheckService, private http: HttpHealthIndicator) {
    const cfAccessOptions: AxiosRequestConfig = {}
    cfAccessOptions.headers = {
      'CF-Access-Client-Id': 'xxx',
      'CF-Access-Client-Secret': 'xxx'
    }

    this.checks.set('api',
      async () => this.http.responseCheck<string>(
        'api',
        'https://api.xxx',
        response => {
          return response.data === 'API is ready'
        },
        cfAccessOptions // Typescript error !
      )
    )
  }

  @Get()
  @HealthCheck()
  check () {
    return this.health.check([...this.checks.values()])
  }

  @Get(':id')
  @HealthCheck()
  checkAuth (@Param('id') id: string) {
    const check = this.checks.get(id)
    if (!check) {
      throw new NotFoundError()
    }

    return this.health.check([check])
  }
}

Steps to reproduce

No response

Expected behavior

Best would be to use axios typings in axios package.

Package version

9.1.1

NestJS version

9.1.2

Node.js version

16.17.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

Typescript 4.8

@BrunnerLivio
Copy link
Member

Release with v9.1.2 by @Tony133 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants