Stricter TypeScript Configuration
Status
Proposed
Date
2025-03-06
Context
As our codebase grows, we've experienced increased development time fixing simple TypeScript errors, particularly around unused variables and parameters. These issues are often only caught during code review rather than during development. Additionally, we've found that our package dependency management is inconsistent, with build-time dependencies sometimes placed in regular dependencies rather than devDependencies.
We need a consistent approach to TypeScript's type checking strictness and package dependency management to improve code quality and reduce maintenance overhead.
Decision
We have decided to:
-
Enable stricter TypeScript compiler options across the monorepo:
-
Enable
noUnusedLocals: true
in the base tsconfig - Enable
noUnusedParameters: true
in the base tsconfig -
Already have
exactOptionalPropertyTypes: true
enabled -
Create automated tooling to help developers transition to and maintain these stricter settings:
-
Create a
strict-ts-fix.ts
script to automatically fix common issues -
Create a
dependency-check.ts
script to identify dependencies that should be in devDependencies -
Document architectural decisions with Architecture Decision Records (ADRs):
- Create an ADR template and directory structure
- Implement a
create-adr.ts
script to streamline the process - Begin documenting significant architectural decisions
Consequences
Positive
- Improved code quality with fewer unused variables and parameters
- Earlier detection of potential issues during development
- Reduced bundle sizes with proper dependency categorization
- Better documentation of significant architectural decisions
- Automated tools to help developers follow best practices
- Consistent approach to code quality across the codebase
Negative
- Short-term increase in TypeScript errors as we enforce stricter rules
- Migration effort required to fix existing code
- Potential need to update CI pipelines to run new checks
- Learning curve for team members to adjust to new processes
Neutral
- Some existing code may need to be refactored to comply with stricter settings
- Regular maintenance required to keep automated tools up to date
Alternatives Considered
-
Gradual enabling of strict settings in specific packages:
-
Rejected because it would lead to inconsistency across the codebase and make it harder to enforce standards
-
Using ESLint rules instead of TypeScript compiler options:
-
Rejected because compiler options provide better integration with IDEs and build tools
-
Manual enforcement through code reviews:
-
Rejected as too time-consuming and error-prone
-
Using third-party dependency analysis tools:
- Rejected in favor of a custom solution that can be tailored to our specific needs