TypeScript with Popular Frameworks

The React Bug That Would Have Cost $2M

9:47 AM, production deploy day. E-commerce checkout redesign ready to ship. 200 hours of development. Marketing campaign scheduled for noon.

Final QA check. Everything looked perfect. Then Sarah (our most thorough QA) noticed something:

"The cart total seems... off?"

I checked. Cart showed $147.99. Should be $847.99. Missing $700. On a production deploy about to go live to 50,000 daily users.

If this shipped, customers would see incorrect prices. Complete orders at wrong amounts. Financial chaos. Estimated loss: $2M+ before we caught it.

Found the bug in 5 minutes thanks to TypeScript:

// The bug - without TypeScript
function CartSummary({ items }) {
  const [total, setTotal] = useState(0);
  
  useEffect(() => {
    // Accidentally using string concatenation instead of addition!
    const sum = items.reduce((acc, item) => acc + item.price, '0');
    setTotal(sum);  // "0123.99..." instead of 847.99
  }, [items]);
  
  return <div>Total: ${total}</div>;
}

With TypeScript, this never compiles:

TypeScript saved us $2M and our reputation.

This article covers using TypeScript with React, Express, and other frameworks - and why proper typing is non-negotiable for production apps.


TypeScript with React

Component Props

Component with Children

useState Hook

useEffect Hook

useRef Hook

Event Handlers

Custom Hooks

Context API


TypeScript with Express (Node.js)

Basic Setup

Typed Request/Response

Middleware

Error Handling

Async Route Handlers


TypeScript with Vue

Component with Script Setup


TypeScript with Angular


Common Patterns

API Response Types

Form Validation


Your Challenge

Build a typed task management system with React and Express:


Key Takeaways

  1. React props - interface for component props

  2. Hooks - useState, useEffect, useRef with types

  3. Event handlers - proper event types

  4. Custom hooks - typed reusable logic

  5. Express - Request, Response, NextFunction types

  6. Middleware - extend Request with custom props

  7. Error handling - typed error classes

  8. Framework-specific - Vue, Angular have their patterns


What I Learned

That cart bug would have shipped to 50,000 users. $2M+ in losses. Financial disaster.

TypeScript caught it instantly:

One type annotation. $2M saved.

Before TypeScript, framework code was fragile. Props changed, components broke. API responses evolved, apps crashed. Runtime bugs everywhere.

After TypeScript, frameworks become predictable. Change a prop type, see all affected components. Modify an API response, find every usage. Compile-time safety for runtime stability.

The lesson: Framework code without types is production gambling. You're betting users won't hit the edge cases. With TypeScript, you know before they do.

Type your frameworks. Sleep better at night.


Next: Migrating from JavaScript to TypeScript

In the next article, we'll cover migrating a real JavaScript project to TypeScript. You'll learn the strategy that converted a 50,000-line codebase with zero downtime.

Last updated