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

Typescript Optional rvn #18

Open
tzarger opened this issue Sep 30, 2022 · 2 comments
Open

Typescript Optional rvn #18

tzarger opened this issue Sep 30, 2022 · 2 comments

Comments

@tzarger
Copy link

tzarger commented Sep 30, 2022

Hello,

I am seeing something that potentially could be error prone or at least when you think you have loaded or query, you may have a null error runtime

image

I see in your tests that you do something like:
await req.rvn?.store(test)
... and ...
await req.rvn?.people?.store(person)

Is there any way to type that so we do not need to know if nullable or not? Even when using
const routeOptions = { rvn: { autoSession: true } }; it still shows as nullable.

@simoneb
Copy link
Member

simoneb commented Oct 2, 2022

req.rvn will only be there if you enable it explicitly, meaning that we can't know whether you did or not. I think the current behavior is correct, and if you want to avoid typing issues you should just tell TS that in your route it is there using req.rvn!

@ilteoood
Copy link
Contributor

ilteoood commented Oct 2, 2022

In addition to what @simoneb said, you can always extend the FastifyRequest and remove the optional constraint

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

No branches or pull requests

3 participants