Eomm / fastify-raw-body

Request raw body
MIT License
44 stars 10 forks source link

Add typescript types for 2.x #10

Closed lucalabs-de closed 1 year ago

lucalabs-de commented 3 years ago

I added the necessary type definitions to import and register the plugin in typescript, the dynamic decoration of the FastifyRequest type is problematic though. I have no idea if that is even possible to type in a .d.ts file. That means that the typescript parser throws an error when trying to access FastifyRequest.rawBody.

A possible workaround for this is to define the type in the application using this plugin.

Eomm commented 3 years ago

Hi, I will check this PR but I'm not a TS user so it takes me more time. As note, I will be "inspired" coping from other fastify plugins (since there are very strong people on TS there 😄 )

For example the fastify-sensible plugin add a request.vary function https://github.com/fastify/fastify-sensible/blob/master/index.d.ts

So I think we could do as it does

Eomm commented 1 year ago

Closing due missing tests

Here is an example of workable PR to add types: https://github.com/Eomm/fastify-overview/pull/61