Course contentsShow
← JavaScript
Lesson 2628 of 2,72353. Type Safety Without TypeScriptFree lesson

Understanding Strict Mode in @ts-check

Learn how strict: true in jsconfig.json enables stricter checks like noImplicitAny and strictNullChecks.

Understanding Strict Mode in @ts-check

You'll learn how enabling strict: true in jsconfig.json activates TypeScript's strictest type-checking rules for your JavaScript project, catching more subtle bugs automatically.

What Strict Mode Does

When you add "strict": true to your jsconfig.json, you're telling the TypeScript compiler to enforce its most rigorous type-checking rules across your JavaScript files that use @ts-check. Think of it like switching from a lenient teacher who lets mistakes slide to one who catches every detail—you'll write safer code, but the bar is higher.

Without strict mode, @ts-check already catches obvious errors like calling undefined functions or accessing missing properties. But strict mode goes further by enabling several additional checks, including:

  • noImplicitAny: Forces you to explicitly type variables that TypeScript can't infer. No more silently treating unknown types as any.
  • strictNullChecks: Treats null and undefined as distinct types that must be handled explicitly. You can't accidentally pass null where only a string is expected.

Why This Matters

Imagine a function expecting a number but receiving null at runtime—your app crashes. With strictNullChecks enabled, @ts-check catches this before you run the code. Similarly, noImplicitAny prevents you from accidentally creating "type blind spots" where bugs can hide.

These stricter rules mean more upfront JSDoc annotations, but they dramatically reduce runtime surprises. You're trading a bit more typing effort for significantly fewer production bugs.

Key Takeaway: Enabling strict: true in jsconfig.json activates TypeScript's strictest rules (noImplicitAny, strictNullChecks, and more), making @ts-check catch subtle type errors that would otherwise slip through to runtime.