Course contentsShow
← TypeScript
Lesson 1596 of 1,79637. Migrating JavaScript to TypeScriptFree lesson

Dealing with Implicit any

Start with noImplicitAny disabled, then enable gradually as you add explicit types to parameters.

Dealing with Implicit any

You'll learn how to migrate a JavaScript codebase by starting with noImplicitAny disabled, then gradually tightening type safety as you add explicit type annotations.

The Strategic Migration Approach

When migrating JavaScript to TypeScript, you face a classic chicken-and-egg problem: your code has no types yet, but TypeScript's strictness flags expect them. The noImplicitAny flag specifically prevents TypeScript from silently giving variables, parameters, and return values the any type when it can't infer something better.

Start permissive, then tighten is the key strategy. With noImplicitAny disabled initially, TypeScript won't complain about all those untyped function parameters and variables in your newly-renamed .ts files. This lets your project compile and keeps you moving forward rather than drowning in hundreds of errors on day one.

The Gradual Tightening Process

Think of it like renovating a house while living in it. You don't demolish everything at once—you work room by room. Similarly, with noImplicitAny: false in your tsconfig.json, you can:

  1. Rename files from .js to .ts without immediate breakage
  2. Add types to function parameters one module at a time
  3. Annotate variables where inference isn't enough
  4. Fix errors incrementally rather than all at once

As you add explicit types (function getUser(id: string) instead of function getUser(id)), those implicit any instances disappear. Once you've covered most of your codebase, you enable noImplicitAny: true. Now TypeScript becomes your safety net, catching any remaining untyped parameters before they cause runtime issues.

Why This Works

This approach respects both pragmatism and safety. You get TypeScript's tooling benefits immediately (autocomplete, refactoring support) without requiring a complete codebase rewrite. The implicit any acts as a temporary escape hatch that you systematically eliminate.

Key Takeaway: Disable noImplicitAny at the start of migration to allow incremental progress, then enable it once you've added explicit types to most of your code—this transforms a months-long nightmare into a manageable, room-by-room renovation.