Repository navigation
Fix: Correct AsyncLocalStorage type parameter to match actual store - #222
Conversation
…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>
There was a problem hiding this comment.
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
RequestContexttoRequestContextData - 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.
|
It would be great if this could be merged 🙌 I ran into this exact problem while following the 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: |
|
@gleb-lobastov as soon as you have time, can you resolve the conflicts? |
|
Ran into this today also. |
# Conflicts: # types/index.d.ts # types/index.test-d.ts
|
I've aligned this branch with
|
|
I also typed the store as |
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
npm run testandnpm run benchmarkand the Code of conduct