davidedantonio / fastify-axios

Add axios http client to your fastify instance
MIT License
39 stars 4 forks source link

Add Types? #25

Open Luizssauro opened 2 years ago

Luizssauro commented 2 years ago

Hello there.

I have a project im working on thats written in TS and i had a hard time figuring it out to work with types.

I had to include a index.d.ts inside the module folder (i know this is horrible practice) and is still not working how it should.

I know it's not enough to open a PR and i would love someone pointing me to the right direction here.

index.d.ts inside node_modules/fastify-axios folder:

import { FastifyPluginCallback } from 'fastify'
import { AxiosDefaults,AxiosRequestHeaders } from 'axios'
import fastify from 'fastify'

declare module 'fastify-axios'

export interface AxiosOpts {
  clients?: {
    [name: string]: {
      baseUrl?: string,
      headers?: AxiosRequestHeaders
    }
  }
}

declare const fastifyAxios: FastifyPluginCallback<AxiosOpts?>

declare module 'fastify' {
  export interface FastifyInstance {
    axios: {
      [name: string]: FastifyPluginCallback
    }
  }
}

export default fastifyAxios
export { fastifyAxios }

I'm using: "fastify": "^4.3.0", "fastify-axios": "^1.2.5", "axios": "^0.27.2",

chiptoma commented 7 months ago

See below:

31