Typescript issues with axios >= 0.27
Toilal opened this issue · comments
Rémi Alvergnat commented
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
Livio Brunner commented