1

I have a class that standardizes API responses. It has a number of member methods, like ResponseNotFound. I currently use a middleware to attach an instance of this class to req.apiResponse. However, the interface Express.Response doesn't have the property apiResponse.

When the type is basic, such as string or () => void I have no problem modifying the Express types. But, in this case, I can't find a way to get the ApiResponse class into my vendor.d.ts file. If I import into my .d.ts file my declarations are no longer ambient. Is there a way to get the ApiResponse class typings into the vendor.d.ts file?

If not, what are my options?

dkimot
  • 2,239
  • 4
  • 17
  • 25
  • While it looks similar, the accepted answer to that question doesn't solve my problem for two reasons. First, the Express typings are implemented differently. Second, the external import leads to my typings no longer being ambient and TypeScript rejects any alterations made. – dkimot Jul 26 '18 at 23:16
  • Can you please provide sample code that you have tried so I can figure out why the approach from the other question isn't working? – Matt McCutchen Jul 26 '18 at 23:18
  • I stand corrected, that solves my problem. Thank you. – dkimot Jul 26 '18 at 23:26

0 Answers0