Course contentsShow
← TypeScript
Lesson 1678 of 1,79638. Common Patterns and AntipatternsFree lesson

Auditing Codebases for any Usage

Tools and search patterns to find all any types in a project and prioritize remediation.

Auditing Codebases for any Usage

You'll learn: How to systematically find every any type in your project and create a prioritized cleanup plan.

Why Audit for any

As your TypeScript codebase grows, any types accumulate like technical debt. They silently spread type unsafety, disable autocomplete, and hide bugs. Before you can eliminate them, you need to find them all—and decide which ones matter most.

Think of it like finding all the unlocked doors in a building: some lead to supply closets (low risk), others to server rooms (critical). You need visibility before you can secure what matters.

Tools for Finding any

1. TypeScript Compiler's --noImplicitAny

Your first line of defense catches implicit any (places where TypeScript infers any because you didn't provide types). This won't find explicit any you wrote deliberately.

2. Search Your Codebase

Simple but effective:

# Find explicit any types
grep -r ": any" src/

# More targeted regex search
grep -rE ": any\b|<any>|\bany\[" src/

3. TypeScript ESLint Rules

Install @typescript-eslint/eslint-plugin and enable:

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

This flags every explicit any in your code with IDE warnings and linting errors.

4. Custom Scripts for Counting

Generate a report showing which files have the most any usage:

grep -r ": any" src/ | cut -d: -f1 | sort | uniq -c | sort -rn

Creating a Prioritization Matrix

Not all any types are equally dangerous. Prioritize by:

  1. API boundaries (highest risk): Functions returning any that spread through your codebase
  2. External library types: Missing @types packages you can install
  3. High-traffic functions: Utilities used everywhere
  4. New feature code: Easier to fix before it grows
  5. Legacy code with low test coverage: Riskiest to refactor, lowest priority

Create a spreadsheet or issue list tracking each instance with impact scores.

Measuring Progress

Set measurable goals:

  • Current baseline: X occurrences of any
  • Monthly reduction target: 10%
  • Team rule: No new any without documented justification

Key Takeaway: Systematic auditing transforms "any creep" from an invisible problem into a trackable, solvable maintenance task—find them all first, then tackle them by priority.