Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Special Types · Lesson 10 of 12

The any Type

A free lesson from Swipe Coding · TypeScript, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
any is TypeScript's overpowered escape hatch — great in a pinch, easy to abuse. ⚠️

Every TypeScript value has a type, but sometimes you need a variable that can hold literally anything and have TypeScript stay completely out of the way. That's what the any type is for — it's an escape hatch that opts a value out of type checking entirely.

let value: any = 4;
value = "hello";   // fine, no error
value = true;      // fine, no error
value = [1, 2, 3]; // fine, no error
A variable typed any accepts a reassignment to any other type, at any point, with no complaints from the compiler.
🤖
This is the part that should make you a little nervous about any. 😬

The real danger of any isn't just that it accepts anything — it's that TypeScript stops checking what you do with it, too. Calling a method that doesn't exist, accessing a property that was never there, passing it somewhere it doesn't belong — all of that compiles without a single warning.

let data: any = { name: "Ada" };

data.nonExistentMethod(); // compiles fine...
// ...then crashes at runtime:
// TypeError: data.nonExistentMethod is not a function
With any, the mistake isn't caught while you're writing the code — it surfaces later, as a runtime crash, which is exactly what TypeScript exists to prevent.

Reaching for any every time a type is inconvenient to write defeats the entire purpose of using TypeScript — you get the extra syntax and the build step, but lose the safety net that's supposed to come with them. any has legitimate uses (gradually migrating old JavaScript, for example), but it should be the exception, not the default.

// Overusing any — silently unsafe:
function total(items: any): number {
  return items.reduce((sum: any, i: any) => sum + i.price, 0);
}

// Prefer a real type instead:
function totalSafe(items: { price: number }[]): number {
  return items.reduce((sum, i) => sum + i.price, 0);
}
totalSafe gives you autocomplete on i.price and an immediate error if you pass the wrong shape — total gives you neither.
Fill in the blank

A variable typed as ____ can be reassigned to any type with no compiler error.

Quick check

Why is overusing any considered risky in a TypeScript codebase?

True or false

Calling a nonexistent method on a value typed any produces a compile-time error.

Keep your streak going in Swipe Coding

Swipe through every level of TypeScript on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →