I am trying to work with TypeScript and Express. I've loaded in the type declarations from Typings and they look like this:
// Generated by typings
// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/7de6c3dd94feaeb21f20054b9f30d5dabc5efabd/express/express.d.ts
declare module "express" {
import * as serveStatic from "serve-static";
import * as core from "express-serve-static-core";
/**
* Creates an Express application. The express() function is a top-level function exported by the express module.
*/
function e(): core.Express;
namespace e {
/**
* This is the only built-in middleware function in Express. It serves static files and is based on serve-static.
*/
var static: typeof serveStatic;
export function Router(options?: any): core.Router;
interface Application extends core.Application { }
interface CookieOptions extends core.CookieOptions { }
interface Errback extends core.Errback { }
interface ErrorRequestHandler extends core.ErrorRequestHandler { }
interface Express extends core.Express { }
interface Handler extends core.Handler { }
interface IRoute extends core.IRoute { }
interface IRouter<T> extends core.IRouter<T> { }
interface IRouterMatcher<T> extends core.IRouterMatcher<T> { }
interface MediaType extends core.MediaType { }
interface NextFunction extends core.NextFunction { }
interface Request extends core.Request { }
interface RequestHandler extends core.RequestHandler { }
interface RequestParamHandler extends core.RequestParamHandler { }
export interface Response extends core.Response { }
interface Router extends core.Router { }
interface Send extends core.Send { }
}
export = e;
}
Now I'm trying to extend the prototype for all Response objects like so:
const express = require('express');
express.response.sendWrapped = function(obj: Object, meta?: Object) {
return this.json({
data: obj
});
};
Now I just need to get the extension into the typings. I would love to just extend this method into the existing definition, much like how I have extended it in the prototype, but I am unsure how to do so.
Since this is a personal extension of the type definition for the library, I do not believe this belongs back with the master typing set and I should not have to modify them manually for my own purposes. What is the best way to extend them in my own way? Can I do it without overriding every other piece dependent on Response?