We are using it succesfully but that is not the issue with the function. Express does not seem to expose a type for the function. Using Request and Response does not work well with the merging. So we need to let TypeScript infer the types by passing it to app.use
The function needs to be passed to app.use directly. I sadly did not find a type for the function that can be used here. Passing it directly to app.use will let TypeScript infer the types
If you put the type Request on the res parameter, it is technically the wrong type as the correct type would be Request<ParamsDictionary, any, any, QueryString.ParsedQs, Record<string, any>> but this is too annoying to write out.
@Ayan - That does not look like a runtime error. That error is definitely produced by TypeScript during compile time. How are you compiling the app? Just tsc or something with webpack?
@Ayan - Yes, you specified that success and error are optional, so a Response might or might not have them. You would either need to check if they are defined before calling them, or remove the question mark.
@Ayan - You need in the declare namespace Express { ... for the type of the argument in the function but also in the responseHelper because you are using it as the type of the argument of res.success too.