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