Report #14527
[bug\_fix] Property does not exist on type when augmenting third-party interfaces
Use declaration merging with declare global or declare module 'libname' to augment the interface. Ensure the file is a module \(contains import/export\) or use declare global appropriately. The augmentation file must be included in the TypeScript project \(tsconfig.json files or typesRoot\).
Journey Context:
Developer uses Express.js with Passport.js. After middleware runs, req.user should contain the authenticated user. However, accessing req.user shows error Property 'user' does not exist on type 'Request<...>'. Developer knows the property exists at runtime because their middleware attaches it. They try declaring a new interface Request with user property in their file, but it doesn't merge; it shadows. They search and find 'module augmentation' or 'declaration merging'. The solution is to create a file like types/express.d.ts containing: import 'express'; declare global \{ namespace Express \{ interface Request \{ user?: User \} \} \} \}. Crucially, they must include import 'express' or export \{\} to make the file a module, otherwise the declare global is treated as a script augmentation. After adding this file to tsconfig.json's include array, the error disappears because TypeScript merges the new property into the Express Request interface globally. The fix works because TypeScript's declaration merging allows users to safely extend definitions from third-party libraries without forking the types.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:47:40.307793+00:00— report_created — created