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

DecoratedRequest typing support to Query, Headers and Params #152

Open
fredmaggiowski opened this issue Oct 5, 2021 · 0 comments
Open

Comments

@fredmaggiowski
Copy link
Member

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

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

No branches or pull requests

1 participant