Back to blog
    Product Engineering

    TypeScript Strict Mode: Why We Enforce It on Every Project

    Steinn Labs··6 min read

    Key Takeaways

    • strictNullChecks alone prevents roughly 30% of runtime errors seen in production
    • The time saved debugging runtime errors compensates for slower initial development within one month
    • Migrate incrementally: start with strictNullChecks then add flags one at a time
    • Budget 1-2 weeks to migrate a medium-sized codebase to strict mode

    The Strict Mode Decision

    Two years ago, we made TypeScript strict mode mandatory on every project. No exceptions. Some engineers pushed back initially. Today, none of them would go back.

    Strict mode enables several compiler flags that catch common errors: strictNullChecks, noImplicitAny, strictFunctionTypes, and others. Together, they force you to handle edge cases that would otherwise become runtime errors.

    What Strict Mode Catches

    Null and Undefined

    The biggest win. Without strictNullChecks, TypeScript lets you access properties on potentially null values without warning. With it enabled, the compiler forces you to handle the null case. This alone prevents roughly 30% of the runtime errors we used to see in production.

    Implicit Any

    Without noImplicitAny, untyped function parameters silently become "any," disabling all type checking for that code path. With strict mode, every parameter must be typed, ensuring the compiler can verify correctness throughout the call chain.

    Function Type Safety

    strictFunctionTypes ensures that callback and event handler types are checked properly, catching bugs where the wrong type of callback is passed to a function.

    The Short-Term Cost

    Yes, strict mode slows you down initially. Type annotations take time. Handling null cases adds code. But the time saved debugging runtime errors in production more than compensates within the first month.

    Migration Strategy

    If you have an existing project without strict mode, do not enable all flags at once. Start with strictNullChecks (the biggest win), fix all errors, then enable noImplicitAny, and continue flag by flag. Budget 1-2 weeks for a medium-sized codebase.

    Frequently Asked Questions

    Should TypeScript strict mode be enabled?

    Yes. Strict mode catches null errors, implicit any types, and function type mismatches at compile time. It prevents roughly 30% of the runtime errors commonly seen in production.

    Does TypeScript strict mode slow down development?

    Initially yes, as you need to add type annotations and handle null cases. But the time saved debugging runtime errors in production more than compensates within the first month.

    How do you migrate to TypeScript strict mode?

    Enable flags incrementally: start with strictNullChecks, fix all errors, then enable noImplicitAny, and continue flag by flag. Budget 1-2 weeks for a medium-sized codebase.

    typescript
    strict-mode
    code-quality
    developer-experience
    best-practices