Skip to content

DecoratedRequest typing support to Query, Headers and Params #152

@fredmaggiowski

Description

@fredmaggiowski

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/[email protected]
os: MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions