Any TypeScript project
Add typed user and session properties to Express Request using module augmentation.
1 import 'express'; 2 3 declare module 'express' { 4 interface Request { 5 user?: { 6 id: string; 7 email: string; 8 role: 'admin' | 'user' | 'guest'; 9 }; 10 session?: { 11 token: string; 12 expiresAt: Date; 13 }; 14 requestId?: string; 15 } 16 }
req.user is typed; window.analytics.track compiles; SVG imports don't error
Sign in to share your feedback and join the discussion.