diff --git a/types/types.d.ts b/types/types.d.ts index d1eed51..91d199b 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -26,7 +26,6 @@ type FastifySession = FastifyPluginCallback void; -type CallbackSession = (err: Error | null, result: Fastify.Session) => void; interface SessionData extends ExpressSessionData { sessionId: string; @@ -80,6 +79,8 @@ interface Signer { } declare namespace fastifySession { + export type CallbackSession = ((err: Error) => void) | ((err: null, result: Fastify.Session) => void) + export interface SessionStore { set( sessionId: string, diff --git a/types/types.test-d.ts b/types/types.test-d.ts index 7643f7f..20d26eb 100644 --- a/types/types.test-d.ts +++ b/types/types.test-d.ts @@ -88,8 +88,10 @@ app.route({ request.sessionStore.set('session-set-test', request.session, () => {}); request.sessionStore.get('', (err, session) => { expectType(err); - expectType(session); - expectType<{ id: number } | undefined>(session.user); + expectType(session); + if (session) { + expectType<{ id: number } | undefined>(session.user); + } }); expectType(request.session.set('foo', 'bar')); expectType(request.session.get('foo'));