Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable specifying interface for context data #48

Merged
merged 5 commits into from May 21, 2021

Conversation

awlayton
Copy link
Contributor

Checklist

This allows specifying types for the data stored in the request context which are then respected by get and set.

npm run test:typescript still passes.

import {requestContext} from 'fastify-request-context'

declare module 'fastify-request-context' {
  interface RequestContextData {
    foo: string
  }
}

// Type is string
const foo = requestContext.get('foo')
// Type for unspecified keys is any as before
const bar = requestContext.get('bar')

@kibertoad
Copy link
Member

Thank you! Could you please add tsd test for this change?

@awlayton
Copy link
Contributor Author

Not sure how my changes could break that test? It passes on my machine with node 16 and I did not change any of the actual code...

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm, seems a flaky test

@kibertoad
Copy link
Member

Will review the test and merge later today.

@kibertoad
Copy link
Member

@awlayton Could you also please add simple example of this new feature into README.md?

@kibertoad
Copy link
Member

And with regards to tests failing - it actually seems to be related to ALS changes in 16.2.0. I've fixed tests to handle errors properly, and will now investigate the actual underlying cause.

@kibertoad
Copy link
Member

Thank you!

@kibertoad kibertoad merged commit fb99bbb into fastify:master May 21, 2021
@kibertoad
Copy link
Member

Published in 2.2.0

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.

None yet

3 participants