I have some express module augmentations. My intention is to be able to do:
request.message('Hello').status(400).json({});
The status
and json
functions are part of the express Response
object. These functions return the Response
object they were called on to allow chaining (a.k.a a fluent API).
I wish to add my own message
function to do much the same. My augmentation looks like so:
import { SomeType } from '...';
declare global {
namespace Express {
interface Response {
// This works.
getSomeType(): SomeType;
// This does not. Typescript thinks the object returned here has ONLY the getSomeType/message functions on it
message(str: string): Response;
}
}
I've tried variations of
message(str: string): Express.Response
And
message(str: string): Response & Express.Response
This made no difference. As before: Typescript thinks the object returned here has ONLY the getSomeType/message functions on it