From e70407f10444b9bfd009f10a09f22ef37277e686 Mon Sep 17 00:00:00 2001 From: Gleb Date: Sun, 15 Jun 2025 13:54:42 +0300 Subject: [PATCH 1/2] Fix: Correct AsyncLocalStorage type parameter to match actual store (RequestContextData) The AsyncLocalStorage was incorrectly typed as RequestContext, but in reality it stores RequestContextData, which is directly accessed via key-value operations (e.g. store[key]). Signed-off-by: Gleb --- types/index.d.ts | 2 +- types/index.test-d.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 303cedc..9b4425a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -54,7 +54,7 @@ declare namespace fastifyRequestContext { } export const requestContext: RequestContext - export const asyncLocalStorage: AsyncLocalStorage + export const asyncLocalStorage: AsyncLocalStorage /** * @deprecated Use FastifyRequestContextOptions instead */ diff --git a/types/index.test-d.ts b/types/index.test-d.ts index 0f62272..62e4d4d 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -5,6 +5,7 @@ import { FastifyRequestContextOptions, RequestContext, RequestContextDataFactory, + RequestContextData, } from '..' import { expectAssignable, expectType, expectError } from 'tsd' import { FastifyBaseLogger, FastifyInstance, RouteHandlerMethod } from 'fastify' @@ -63,7 +64,7 @@ expectError(() => ({ log: 'dummy' })) expectType(app.requestContext) expectType(requestContext) -expectType>(asyncLocalStorage) +expectType>(asyncLocalStorage) const getHandler: RouteHandlerMethod = function (request, _reply) { expectType(request.requestContext) From 4649c16eabfe2a07b33ea421aeebf50b94ee1bdf Mon Sep 17 00:00:00 2001 From: Tony133 Date: Thu, 3 Dec 2026 21:42:37 +0100 Subject: [PATCH 2/2] fix(types): type the store as Partial --- types/index.d.ts | 2 +- types/index.tst.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 6f0c139..6bfcfa2 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -54,7 +54,7 @@ declare namespace fastifyRequestContext { } export const requestContext: RequestContext - export const asyncLocalStorage: AsyncLocalStorage + export const asyncLocalStorage: AsyncLocalStorage> export const fastifyRequestContext: FastifyRequestContext export { fastifyRequestContext as default } } diff --git a/types/index.tst.ts b/types/index.tst.ts index c1c70e8..89f1072 100644 --- a/types/index.tst.ts +++ b/types/index.tst.ts @@ -66,7 +66,7 @@ expect().type.not.toBeAssignableFrom(() => ({ log: 'd expect(app.requestContext).type.toBe() expect(requestContext).type.toBe() -expect(asyncLocalStorage).type.toBe>() +expect(asyncLocalStorage).type.toBe>>() const getHandler: RouteHandlerMethod = function (request, _reply) { expect(request.requestContext).type.toBe()