-
-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Description
Description
Quoting the only documentation within the code for extending the express types:
declare global {
namespace Express {
// These open interfaces may be extended in an application-specific manner via declaration merging.
// See for example method-override.d.ts (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/method-override/index.d.ts)
interface Request {}
interface Response {}
interface Locals {}
interface Application {}
}
}
The URL refers to a piece of code that uses the following syntax:
declare namespace Express {
export interface Request {
originalMethod?: string | undefined;
}
}
This does not work. TypeScript also deprecated namespaces, making this doubly incorrect.
The only correct way I've found of doing this is now:
declare module "express-serve-static-core" {
export interface Response {
originalMethod?: string | undefined;
}
}
There is very little documentation online that shows this, and I cannot find documentation anywhere on expressjs.com for extending these (or for anything at all TypeScript-related, which seems pretty odd to me).
Expectations
I would expect to find adequate documentation on expressjs.com or somewhere that documents usage of express with TypeScript specifically, and that covers extending Request / Response / Locals / Application interfaces in detail, documenting the correct methods that work.