Skip to content

Lack of TypeScript documentation - Extending Request / Response / etc. #6267

@CodeSmith32

Description

@CodeSmith32

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions