fastify-plugin: Broken Typescript types when defining options and done

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

Plugin version

4.5.0

Node.js version

18

Operating system

Linux

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

Description

I can’t define a plugin with options and done callback

import fp from "fastify-plugin";

export default fp(function Health(fastify, opts, done) {
  fastify.get("/health", (req, res) => {
    res.send();
  });
});

Results in TS7006: Parameter 'opts' implicitly has an 'any' type.

Steps to Reproduce

See description.

Workaround:

import fp from "fastify-plugin";
import { FastifyPluginCallback } from "fastify";

const plugin: FastifyPluginCallback = function Health(fastify, opts, done) {
  fastify.get("/health", (req, res) => {
    res.send();
  });

  done();
};

export default fp(plugin);

Expected Behavior

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

Sure, I think I can create a PR this weekend.