I would like to add a property, id , to the Express Request interface. Express has a specific type definition. I tried all kinds of interface instructions for merging, all of which lead to errors or do not work.
I get access to express typing using the import of ES6 style modules: import * as express from 'express';
I tried merging with the Request object in the Express namespace.
declare module Express { export interface Request { id: number; } }
It silently does nothing. I tried merging with the actual module instead of the namespace, following the instructions of the new 1.8 compiler that I am using:
import { Request } from 'express'; declare module 'express' { interface Request { id: number; } }
These errors are because Module augmentation cannot introduce new names in the top level scope.
When I open the actual express.d.ts file, it looks like module e { ... } containing all the interfaces inside declare module "express" { ... } , which contains the line export = e; . Maybe this is somehow a problem due to naming of the namespace?
How do you do it right?
typescript
David pfeffer
source share