Course contentsShow
← TypeScript
Lesson 877 of 1,79620. The any Escape HatchFree lesson

any Spreads Through Your Codebase

Learn how any values propagate through function calls and assignments, infecting other parts of your code.

any Spreads Through Your Codebase

You'll learn: How any values act like a contagion, propagating type unsafety through function calls and assignments to infect distant parts of your code.

The Contagion Problem

When you use any, you don't just lose type safety at that single point—any spreads like a virus through your codebase. Any value derived from any also becomes any, and any function that returns any passes that type unsafety to whoever calls it.

Think of it like a drop of ink in water: it doesn't stay contained where you put it. It diffuses outward, contaminating everything it touches.

How any Spreads

Through Variable Assignment

const untypedData: any = getUserInput();

// infected becomes any too
const infected = untypedData.someProperty;

// stillInfected is also any
const stillInfected = infected + 10;

Through Function Returns

function parseValue(input: string): any {
  return JSON.parse(input);
}

// result is any, even though we didn't annotate it
const result = parseValue('{"name": "Alice"}');

// name is also any
const name = result.name;

// Everything downstream is now untyped
const uppercased = name.toUpperCase();

Through Array and Object Operations

const anyArray: any[] = getItems();

// item is any
anyArray.forEach(item => {
  // properties is any
  const properties = item.data;
  
  // spreadingFurther is any
  const spreadingFurther = properties.value;
});

Why This Matters

Every any is a point of failure that radiates outward. A single poorly-typed API response can make dozens of variables lose their types. You might think you're only "cheating" in one place, but the type system can't help you anywhere downstream either.

Key Takeaway: any doesn't stay contained—it spreads through assignments, returns, and property access, creating expanding zones of type unsafety that can reach far beyond where you originally used it.