fastify/fastify-postgres

Typescript types missing for FastifyRequest and RouteShorthandOptions when using the transact route option

bdun94 opened this issue · 1 comments

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.0.0

Plugin version

5.0.0

Node.js version

16.16.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.4

Description

When attempting to use the transact route option using typescript, passing in the transact route options and referencing pg from the request object throws typescript type errors. This is because because pg has not been added to FastifyRequest and

interface FastifyPostgresRouteOptions {
  transact: boolean | string;
}

has not been added for pg for RouteShorthandOptions

Steps to Reproduce

fastify.post(
    '/',
    {
      pg: { transact: true }, // Throws type error for RouteShorthandOptions
    },
    async (req, _reply) => {
      req.pg.query('SELECT * FROM table') // Throws type error for FastifyRequest
    }
  );

Expected Behavior

Using the route transact option should not cause compile errors in typescript

Sorry for the accidental close, wanted to comment that I've added a PR for this since it seems easy enough to resolve. Let me know if there's anything else I need to do or if there's an issue with this PR