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

Update the README to clarify a scenario where a typed property in the context can unexpectedly be undefined #95

Merged
merged 4 commits into from
Dec 20, 2021

Conversation

silenceisgolden
Copy link
Contributor

Checklist

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).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Member

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?

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

@mcollina mcollina merged commit 3aa4c66 into fastify:master Dec 20, 2021
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