From 636b3435428728498a3cc93191861d3471a18eae Mon Sep 17 00:00:00 2001 From: Ilia Baryshnikov Date: Thu, 26 Oct 2023 19:03:31 +0200 Subject: [PATCH] fix!: jsonify req.body --- src/typed-fastify.ts | 2 +- test/fixtures.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/typed-fastify.ts b/src/typed-fastify.ts index 4438ff5..84e29ab 100644 --- a/src/typed-fastify.ts +++ b/src/typed-fastify.ts @@ -350,7 +350,7 @@ interface Request< readonly operationPath: Path; readonly method: ROptions['method']; // A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request. - readonly body: ROptions['method'] extends 'GET' ? never : Get; + readonly body: ROptions['method'] extends 'GET' ? never : Jsonify>; readonly routeOptions: Id>; readonly routerMethod: ROptions['method']; readonly headers: Get; diff --git a/test/fixtures.ts b/test/fixtures.ts index f0f31fe..30c5245 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -30,7 +30,8 @@ export const defaultService: Service = { }, 'POST /jsonify': (req, reply) => { const { date } = req.body; - return reply.status(200).send({ date: date.toJSON() }); + date.charAt; // ok for string, not ok for Date + return reply.status(200).send({ date: new Date(date).toJSON() }); }, 'POST /': (req, reply) => { if (req.operationPath !== 'POST /') {