Q45: What is Module Augmentation?
Module Augmentation allows developers to extend existing external third-party module declarations by opening their namespace scope in local code files.
Extending Express Request Interface
import express from 'express';
declare module 'express-serve-static-core' {
interface Request {
currentUser?: { id: string; role: string };
}
}💡 Augments the internal Express Request interface to include custom currentUser properties globally.
Key Takeaways
- Use module augmentation to add properties to external library types.