fastify / help

Need help with Fastify? File an Issue here.
https://www.fastify.io/
65 stars 8 forks source link

Extend FastifyRequest using FastifyPluginAsyncTypebox #830

Open patilanz opened 1 year ago

patilanz commented 1 year ago

💬 Question here

Hey, i'm trying to extend FastifyRequest while using type-provider-typebox.

  let fastify = Fastify(opts).withTypeProvider<TypeBoxTypeProvider>();

  // then in another file
  const route: FastifyPluginAsyncTypebox = async (instance, opts) => {
  instance.register((request, reply) => {
    request.user; // not defined
  });

}
  // maybe the solution is something like this but I'm not sure how:
  // fastify.d.ts
  declare module "fastify" {
    export type FastifyNewRoute = FastifyPluginAsyncTypebox & {
          instance: FastifyInstance... // now sure what to do next
    };
  } 
mcollina commented 1 year ago

cc @fastify/typescript