Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

Module Augmentation in TypeScript: Three Patterns and One Foot-Gun

DEV Community·Gabriel Anhaia·29 days ago
#OizQ9mJt
Reading 0:00
15s threshold

Book: The TypeScript Type System — From Generics to DSL-Level Types Also by me: The TypeScript Library — the 5-book collection My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub A team writes an Express middleware that decodes a JWT and attaches the decoded user to the request. The handler downstream reads req.user.id and the editor flags it red. Property 'user' does not exist on type 'Request' . Someone adds (req as any).user.id , review approves, the file ships. Weeks later the same as any hides a refactor where user becomes currentUser upstream, and nobody catches it because the cast erased the type. A 500 lands in production over the weekend. That cast was unnecessary. The TypeScript type system has a way to say Request has a user field now, in this codebase, applied to every import of Request everywhere.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More