You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I am trying to use a custom middleware which injects the users company in either the request or response objects. I don't want to use declare global for this, as not all of my requests in the app will use this custom middleware. I tried a couple of things, and everything gives me some sort of typescript error
Nothing works. All errors are something along the lines of this one:
Types of property 'locals' are incompatible.
Property 'company' is missing in type 'Record<string, any> & Locals' but required in type '{ company: GetResult<{ id: string;}, unknown> & {}; }'.
How to properly extend either the request or response objects?????
The text was updated successfully, but these errors were encountered:
I'm afraid that you have to extend the Request interface from Express namespace globally (as an optional property), because modifying request or response is a side-effect that can't be expressed in TypeScript.
FYI Express type definitions are maintained in the DefinitelyTyped project and there are no Express 5 specific definitions (I think that the v4 types should be good enough for most use cases).
Hi. I am trying to use a custom middleware which injects the users company in either the request or response objects. I don't want to use
declare global
for this, as not all of my requests in the app will use this custom middleware. I tried a couple of things, and everything gives me some sort of typescript errorI also tried all of these interfaces:
Nothing works. All errors are something along the lines of this one:
How to properly extend either the request or response objects?????
The text was updated successfully, but these errors were encountered: