Problem Statement
Augment a third-party module by adding a function via .d.ts.
Explanation
Create a `.d.ts` in your `types/` folder, reopen the module with `declare module`, and add the new types. Keep all patches in one place so upgrades are safe and your codebase stays clean.
Code Solution
SolutionRead Only
/* types/express-augment.d.ts */
declare module 'express' {
interface Request {
userId?: string;
}
}
// usage in app code
import express from 'express';
const app = express();
app.use((req, _res, next) => { req.userId = 'u1'; next(); });