-
Notifications
You must be signed in to change notification settings - Fork 13
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
Update the README to clarify a scenario where a typed property in the context can unexpectedly be undefined #95
Update the README to clarify a scenario where a typed property in the context can unexpectedly be undefined #95
Conversation
… context can unexpectedly be undefined.
README.md
Outdated
const foo = requestContext.get('foo') | ||
``` | ||
|
||
This also occurs if you have `"strict": true` configured, since enabling Typescript strict mode includes turning on `"strictNullChecks"`. For a discussion about how to work around this and the pros/cons of doing so, please see [fastify/fastify-request-context#93](https://github.com/fastify/fastify-request-context/issues/93). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also occurs if you have `"strict": true` configured, since enabling Typescript strict mode includes turning on `"strictNullChecks"`. For a discussion about how to work around this and the pros/cons of doing so, please see [fastify/fastify-request-context#93](https://github.com/fastify/fastify-request-context/issues/93). | |
This also occurs if you have `"strict": true` configured, since enabling Typescript strict mode includes turning on `"strictNullChecks"`. For a discussion about how to work around this and the pros/cons of doing so, please read this [issue #93](https://github.com/fastify/fastify-request-context/issues/93). |
@@ -104,6 +104,25 @@ const foo = requestContext.get('foo') | |||
const bar = requestContext.get('bar') | |||
``` | |||
|
|||
If you have `"strictNullChecks": true` configured for Typescript project, you will notice that the type of the returned value can still be `undefined` even though the `RequestContextData` interface has a speicfic type: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a ## Typescript
section above to improve even more the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Checklist
npm run test
andnpm run benchmark
and the Code of conduct