cmorten / opine

Minimalist web framework for Deno ported from ExpressJS.
https://github.com/cmorten/opine/blob/main/.github/API/api.md
MIT License
854 stars 43 forks source link

Can't assign new properties to "req" #45

Closed abbasogaji closed 4 years ago

abbasogaji commented 4 years ago

Issue

Can't assign new properties to "req" Setup:

For example; req.user (throws an error since Property 'user' does not exist on type 'Request<ParamsDictionary, any, any>')

Details

Please replace this quote block with the details of the feature / bug you wish to be addressed. If it is a bug please do your best to add steps to reproduce.

asos-craigmorten commented 4 years ago

Hi @abbasogaji can you provide some more details about where you are seeing this error + a minimal reproduceable example?

This looks likely to be a type error because the Opine Request type on the req object doesn’t allow arbitrary properties - if you wish to extend the object with your own properties then I would expect that you define your own type that extends the Opine Request type. Alternatively if you are not interested in using types you can use Opine in pure JavaScript files.

If you are looking to store properties and pass them between middleware, the recommended way is to use the res.locals object. Please see the docs —> https://github.com/asos-craigmorten/opine/blob/main/.github/API/response.md#reslocals