nearform / fastify-ravendb

Fastify RavenDB connection plugin
5 stars 0 forks source link

Typescript Optional rvn #18

Open tzarger opened 1 year ago

tzarger commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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