Skip to content

Commit

Permalink
fix(ts): extends FastifyContextConfig (#50)
Browse files Browse the repository at this point in the history
* Add missing route config type

* improve test

---------

Co-authored-by: Manuel Spigolon <[email protected]>
  • Loading branch information
FabianFrank and Eomm authored Jul 15, 2023
1 parent 386404a commit ee5f4c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"homepage": "https://github.com/Eomm/fastify-raw-body#readme",
"devDependencies": {
"@types/node": "^20.1.0",
"fastify": "^4.10.0",
"fastify": "^4.19.0",
"standard": "^17.0.0",
"tap": "^16.2.0",
"tsd": "^0.28.0"
Expand Down
4 changes: 4 additions & 0 deletions plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ declare module 'fastify' {
interface FastifyRequest {
rawBody?: string | Buffer
}

interface FastifyContextConfig {
rawBody?: boolean
}
}

type FastifyRawBody = FastifyPluginCallback<fastifyRawBody.RawBodyPluginOptions>
Expand Down
7 changes: 7 additions & 0 deletions test/types/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expectType } from 'tsd'

import fastifyFactory from 'fastify'
import rawBodyPlugin, { RawBodyPluginOptions } from '../../plugin'

Expand All @@ -15,3 +17,8 @@ fastify.register(rawBodyPlugin, options2)
fastify.register(rawBodyPlugin, options3)
fastify.register(rawBodyPlugin, options4)
fastify.register(rawBodyPlugin, options5)

fastify.get('/', { config: { rawBody: true } }, (request, reply) => {
expectType<boolean | undefined>(request.routeConfig.rawBody)
return "rawBody enabled"
})

0 comments on commit ee5f4c2

Please sign in to comment.