Skip to main content
btheo.com btheo.com > press start to play
NEW POST: NODE.JS SECURITY 2025 OPEN FOR FREELANCE 10+ YEARS EXP REACT × NODE × AWS NEW POST: NODE.JS SECURITY 2025 OPEN FOR FREELANCE 10+ YEARS EXP REACT × NODE × AWS
GOTCHA · 07 MAY 2026 · NOTE #029 ESC
GOTCHA NOTE #029

Every `any` Is a Bug Waiting

The problem:

const data: any = fetchFromAPI();
data.email; // TypeScript doesn't check this. Crash if email doesn't exist.

You type-checked everything else. Then you hit something unknown and use any. It feels safe.

It’s not. any is “I’m opting out of type safety here.”

The fix: Use unknown

const data: unknown = fetchFromAPI();
// data.email; // ✗ Error: unknown doesn't have email property
const typed = data as { email: string }; // ✓ Intentional cast
typed.email; // Now safe

Or parse with zod:

const userSchema = z.object({ email: z.string() });
const data = userSchema.parse(fetchFromAPI());
data.email; // Type-safe, validated

Enforce with eslint:

{
"rules": {
"@typescript-eslint/no-explicit-any": "error"
}
}

If you must use any, leave a comment:

// TODO: type this properly once the API schema is finalized
const data: any = fetchFromAPI();

Every any is a TODO. Close them before shipping.