Skip to content

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

Closed
@bdun94

Description

@bdun94

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions