From 18b48a81f0a80cff6882cae72c325917252425f7 Mon Sep 17 00:00:00 2001 From: Nacy Dev Date: Mon, 2 Nov 2026 06:47:44 +0700 Subject: [PATCH] fix(types): allow optional error parameter in CallbackSession --- types/index.d.ts | 2 +- types/index.tst.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 8e7b89f..1ba59c0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -27,7 +27,7 @@ type FastifySession = FastifyPluginCallback void -type CallbackSession = (err: any, result?: Fastify.Session | null) => void +type CallbackSession = (err?: any, result?: Fastify.Session | null) => void interface ExpressSessionData { /** The cookie properties as defined by express-session */ diff --git a/types/index.tst.ts b/types/index.tst.ts index 2da05aa..9b56b2e 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -26,6 +26,32 @@ class EmptyStore { destroy (_sessionId: string, _callback: Function) {} } +const customTypedStore: SessionStore = { + set (_sessionStoreId, _session, callback) { + callback() + }, + get (_sessionStoreId, callback) { + callback() + callback(null) + callback(null, null) + callback(null, undefined) + callback(new Error('failed')) + callback(new Error('failed'), null) + callback(null, { + cookie: { + originalMaxAge: null + }, + foo: 'bar' + }) + }, + compareAndSet (_sessionStoreId, _expectedGeneration, _session, callback) { + callback() + }, + destroy (_sessionStoreId, callback) { + callback() + } +} + declare module 'fastify' { interface Session { user?: { @@ -68,6 +94,10 @@ app.register(plugin, { secret, store: new EmptyStore() as any }) +app.register(plugin, { + secret, + store: customTypedStore +}) expect(app.register).type.not.toBeCallableWith(plugin, { secret, store: new RedisStore({ client: createClient() })