Common checkJs Error Patterns
You'll learn how to recognize and fix the most frequent type errors that surface when you enable checkJs or convert JavaScript files to TypeScript during migration.
When you enable type-checking on existing JavaScript code, TypeScript suddenly starts reporting errors that were silently lurking in your codebase. These aren't new bugs—they were always there—but now the compiler can see them. Understanding the common patterns helps you fix them quickly and systematically.
The Top Patterns You'll Encounter
1. Implicit any from untyped function parameters
JavaScript functions often lack parameter documentation. TypeScript sees these as any by default:
// JavaScript - no complaints
function greet(name) {
return "Hello, " + name.toUpperCase();
}
With checkJs, TypeScript flags name as implicitly any. Fix it with JSDoc or by converting to TypeScript.
2. Potentially null or undefined values
JavaScript code frequently doesn't handle nullish values. With strictness, these become visible errors—attempting to call methods on values that might not exist.
3. Type mismatches from dynamic behavior JavaScript's flexibility means variables change types freely. A variable that starts as a string might become a number, breaking type expectations downstream.
4. Missing or incorrect property access Typos in property names, accessing properties that don't exist, or assuming object shapes that aren't guaranteed—all become compile-time errors.
5. Array operations assuming non-empty arrays
Code that accesses array[0] without checking if the array has elements will trigger errors when noUncheckedIndexedAccess is enabled.
Quick Wins
Most checkJs errors fall into these categories. The fix is usually adding explicit types via JSDoc, adding runtime checks, or restructuring to eliminate the ambiguity that JavaScript allowed but TypeScript questions.
Key Takeaway: When enabling checkJs, expect errors around implicit any, null safety, type inconsistency, property access, and array assumptions—these are JavaScript's hidden risks now made visible.