'How to extend express request and response interfaces?
I want to extend express Request and Response interfaces, i do it like this:
import express from 'express';
interface ResponseBody<T = any> {
data?: T;
error?: string;
}
declare global {
namespace Express {
export interface Request<T = any> extends express.Request {
body: T;
}
export interface Response extends express.Response {
json: (body?: ResponseBody) => this;
}
}
}
In my code i can access req.body and res.json with no errors, but when i'm trying to access other properties of express.Request or express.Response (e.g. req.params), i get an error in VS Code that this property doesn't exist in Express.Request or Express.Response type, although my interfaces extend original Request and Response types.
Why i'm not able to use express.Request and express.Response properties?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
