Skip to content

ESLint error/warning @typescript-eslint/no-misused-promises when passing async returning handler hook in Fastify route parameter #6513

@segevfiner

Description

@segevfiner

Prerequisites

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

Fastify version

5.7.4

Plugin version

No response

Node.js version

22.22.0

Operating system

macOS

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

26.2

Description

ESLint is getting confused by something in the Fastify types or they are not defined accurately enough for it that such code:

import { FastifyPluginAsync, FastifyRequest } from "fastify";

async function preHandler(request: FastifyRequest) {
  console.log(request.query);
}

const example: FastifyPluginAsync = async (fastify, _opts): Promise<void> => {
  fastify.get("/", { preHandler }, async function () {
    return "this is an example";
  });
};

export default example;

Gives you:

fastify-async-pre-handler-issue/src/routes/example/index.ts
  8:22  error  Promise-returning function provided to property where a void return was expected  @typescript-eslint/no-misused-promises

I'm not entirely sure whether its an issue in the Fastify types or in typescript-eslint's implementation of that rule.

In reality, async/Promise is required there, or the callback will have to receive a done callback that is must call or Fastify will hang.

cc @giladnavot

Link to code that reproduces the bug

https://github.com/segevfiner/fastify-async-pre-handler-issue.git

Expected Behavior

Given project should be lint free.

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