Skip to content

Fix: Correct AsyncLocalStorage type parameter to match actual store - #222

Open
gleb-lobastov wants to merge 1 commit into
fastify:mainfrom
gleb-lobastov:patch-1
Open

gleb-lobastov wants to merge 1 commit into
fastify:mainfrom
gleb-lobastov:patch-1

Conversation

@gleb-lobastov

Copy link
Copy Markdown

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]).

Checklist

…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 <gleb-lobastov@users.noreply.github.com>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@gurgunday gurgunday left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Fdawgs
Fdawgs requested a review from Copilot August 14, 2025 17:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a type inconsistency in the AsyncLocalStorage type parameter. The AsyncLocalStorage was incorrectly typed as storing RequestContext when it actually stores RequestContextData.

  • Corrects the AsyncLocalStorage type parameter from RequestContext to RequestContextData
  • Updates type test to properly validate the AsyncLocalStorage stores RequestContextData

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@tobiasdcl

Copy link
Copy Markdown

It would be great if this could be merged 🙌

I ran into this exact problem while following the Usage outside of a request as described in the readme:

import { asyncLocalStorage } from '@fastify/request-context';

it('should set request context', () => {
  asyncLocalStorage.run({}, async () => {
    requestContext.set('userId', 'some-fake-user-id');
    someCodeThatUsesRequestContext(); // requestContext.get('userId') will work
  })
})

results in TS error:

Argument of type '{}' is not assignable to parameter of type 'RequestContext'.
      Type '{}' is missing the following properties from type 'RequestContext': get, set, getStore

@Tony133

Tony133 commented Sep 3, 2026

Copy link
Copy Markdown
Member

@gleb-lobastov as soon as you have time, can you resolve the conflicts?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants