Skip to content

Incorrect type definition for genReqId in FastifyServerOptions #4748

@sergburn

Description

@sergburn

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.17.0

Plugin version

No response

Node.js version

Irrelevant

Operating system

Linux

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

Irrelevant

Description

The type of genReqId server option implies its only argument is an instance of FastifyRequest:

    genReqId?: <...>(req: FastifyRequest<...>) => string,

However, in practice it is given RawRequest (e.g. http.IncomingMessage):

function routeHandler (req, res, params, context, query) {
    const id = genReqId(req)

while FastifyRequest is created only later in this function.

Steps to Reproduce

To reproduce, let's extend the test in test/genReqId.js:

    genReqId: function (req) {
      t.hasProp(req, 'id')
      t.hasProp(req, 'raw')
      return 'a'
    }

This test will now fail, because these two props normally found in FastifyRequest instance do not actually exist. (Well, id value is supposed to be provided by genReqId in the first place)

Expected Behavior

The type definition should be something like this:

genReqId?: <...>(req: RawRequest) => string,

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bugtypescriptTypeScript related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions