mia-platform/custom-plugin-lib

DecoratedRequest typing support to Query, Headers and Params

fredmaggiowski opened this issue · 0 comments

The feauture or bug you are proposing

Extend DecoratedRequest TypeScript support to Querystring, Headers and Params too.

The description of the bug or the rationale of your proposal

Right now the [DecoratedRequest interface](https://github.com/mia-platform/custom-plugin-lib/blob/9f20da345f208c391527c9c74e4bb7bcbc2955c2/index.d.ts#L60) allows to specify the Generic only for the inner FastifyRequest body, meaning that if I can't specify the shape on any other request parameter (being Querystring, Headers or Params).

A snippet of code for replicating the issue or showing the proposal usage if applicable


interface HelloQueryParameters {
    who?: string
}

interface HelloRequest {
    Querystring?: HelloQueryParameters
}

service.addRawCustomPlugin('GET', '/hello', async function (request:DecoratedRequest<HelloRequest>, reply:FastifyReply<any>) {
        return { message: `Hello ${request.getUserId() || (request.query as HelloQueryParameters).who}` }
}, schema)

In the snippet above, request.query is threated as unknown

The expected result for your bug


service.addRawCustomPlugin('GET', '/hello', async function (request:DecoratedRequest<HelloRequest>, reply:FastifyReply<any>) {
        return { message: `Hello ${request.getUserId() || request.query.who}` }
}, schema)

Your environment

node: v12.17.0
custom-plugin-lib: @mia-platform/custom-plugin-lib@4.1.1
os: MacOS