What does the following module augmentation achieve? // In express.d.ts import ‘express’; declare module ‘express’ { interface Request { user?: { id: string }; } }

TypeScript Professional Hard

TypeScript Professional — Hard

What does the following module augmentation achieve? // In express.d.ts import ‘express’; declare module ‘express’ { interface Request { user?: { id: string }; } }

Key points

  • Declaration merging in TypeScript allows extending existing types
  • The 'user' property is added to the Request interface
  • This augmentation does not create a new interface or modify the express package's source types

Ready to go further?

Related questions