Menu

1 / 2

as const Is the Best Single Feature TypeScript Has Shipped in 5 Years

DEV Community·Gabriel Anhaia·6 months ago
#3SdyWBIW
#pattern#typescript#programming#webdev#const
Reading 0:00
15s threshold

Book: TypeScript Essentials — From Working Developer to Confident TS, Across Node, Bun, Deno, and the Browser

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

You add a new status to your app. The string "archived" goes

into a constant array at the top of the file, and a switch

statement in the reducer handles the new case. CI is green. You

ship.

Two days later a teammate adds "deleted" to the array and

forgets the reducer. The compiler does not flag it. The status

list is typed as string[] . The reducer parameter is typed as

string . Every status in the world satisfies that signature.

The bug ships behind a feature flag. Nobody catches it for a

week, until a customer ticket arrives asking why deleted items

still appear in the active list.

That bug is one keyword away from impossible. The keyword is

as const .…

Continue reading — create a free account

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