TypeScript's Strictness Becomes a Team Decision
As TypeScript adoption becomes standard in frontend development, teams are debating how rigidly to configure its strictness settings. While some advocate for maximum strictness to reduce runtime errors and improve long-term maintainability, others warn that overly strict rules can slow down development and frustrate engineers. Experts like Josh Goldberg recommend pairing TypeScript with robust linting rules to find a practical balance.
- The `strict` flag in a `tsconfig.json` file is a shorthand that enables a suite of stricter type-checking options, including `noImplicitAny`, `strictNullChecks`, `strictFunctionTypes`, and `strictPropertyInitialization`. Teams can, however, enable this master switch while still overriding individual rules to tailor the strictness to their specific needs. - When creating a new project with `tsc --init`, the resulting `tsconfig.json` file has the `strict` option enabled by default, making it the recommended starting point for new TypeScript projects. - Migrating a large, existing JavaScript codebase to TypeScript often involves a gradual increase in strictness. A common strategy is to start by addressing `noImplicitAny` errors to ensure all variables have explicit types, followed by enabling `strictNullChecks` to handle `null` and `undefined` cases explicitly. - According to one case study, a team at Hazelcast found that simply adopting TypeScript without strictness settings resulted in no significant change in their bug rate (averaging 9.66 bugs per month before and 10 after). However, after incrementally enabling all strict mode flags, their bug rate dropped to 3.3 per month. - Research suggests that TypeScript can detect about 15% of common bugs at the compilation stage, which saves developer time that would otherwise be spent on debugging. Furthermore, studies indicate that strict configurations can lead to 25-40% faster refactoring cycles. - By 2024, over 90% of frontend developers reported using TypeScript, with 53% viewing it as the future of web development. This widespread adoption is reflected in the job market, where listings requiring TypeScript experience saw a 40% increase compared to the previous year. - "Type-aware linting," a feature of `typescript-eslint`, allows lint rules to use TypeScript's type information, enabling more powerful checks than traditional linters that only analyze one file at a time. This allows for catching issues like unhandled promises (`no-floating-promises`) or misuse of promises in conditional logic (`no-misused-promises`). - While strictness improves code quality, it introduces a compilation step and can increase the initial cognitive load on developers, requiring them to be more explicit about types and handle edge cases upfront rather than addressing them at runtime.