Skip to content

FastifyInterface TypeScript augmentation when using namespaces聽#321

Description

@chiptoma

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch @fastify/jwt@7.2.4 for the project I'm working on.

When using the namespace option, the fastify.jwt object no longer contains the JWT interface, but the namespace objects.

In my case, I created two namespaces auth and refresh and the fastify.jwt now contains auth: JWT, refresh: JWT.

Unfortunately, I wasn't able to override the augmentation, so I commented it out for the moment.

Maybe this should be left for the implementation to be typed.

Here is the diff that solved my problem:

diff --git a/node_modules/@fastify/jwt/types/jwt.d.ts b/node_modules/@fastify/jwt/types/jwt.d.ts
index d9bc2b4..7d1605b 100644
--- a/node_modules/@fastify/jwt/types/jwt.d.ts
+++ b/node_modules/@fastify/jwt/types/jwt.d.ts
@@ -13,9 +13,11 @@ import {
 } from 'fastify'
 
 declare module 'fastify' {
-  interface FastifyInstance {
-    jwt: fastifyJwt.JWT
-  }
+  // PATCH: If namespaces are used, the `jwt` object will contain the namespaces as a property.
+  // This augmentation prevents later augmentations from overwriting the namespace property.
+  // interface FastifyInstance {
+  //   jwt: fastifyJwt.JWT
+  // }
 
   interface FastifyReply {
     jwtSign(payload: fastifyJwt.SignPayloadType, options?: fastifyJwt.FastifyJwtSignOptions): Promise<string>

This issue body was partially generated by patch-package.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions