0014 - Adopt Typescript Strict flag
Context and Problem Statement
strictflag enables a wide range of type checking behavior that results in stronger guarantees of program correctness. Turning this on is equivalent to enabling all of the strict mode family options.
Of particular note is the Strict Null Checks. By default TypeScript will ignore
undefined allowing them to be used for any types. When
strictNullChecks are enabled
they must be explicitly allowed in the type definition.
Typescript strict mode plugin
The Typescript strict mode plugin is a TypeScript plugin that allows you to progressively turn on strict mode on a file by file basis. This will allow us to progressively update our codebase to support strict mode without requiring a significant initial engineering effort.
- Keep strict disabled - We will continue to run into null issues, and code quality will be lower than it could be.
- Enable strict flag immediately - Turn on the strict flag immediately and assign an engineer to resolve all errors caused by it. This will take a long time, and result in a multitude of conflicts.
- Progressively enable strict flag - Use the TypeScript plugin to migrate files one by one.
Chosen option: Progressively enable strict flag.
- We can immediately start using the strict flag.
- Lower initial developer effort.
- Migration will be slower.
- We will continue to have parts of the code with null issues.
- Might lead to false security if a file is strict but uses non-strict dependencies.
- Few best practices.
Files to be updated
- libs/common: 310
- models: 174
- services: 40
- abstractions: 45
- libs/angular: 64
- libs/node: 11
- libs/electron: 10
- apps: 309
- web: 163
- browser: 80
- desktop: 30
- cli: 36
There are several potential pitfalls related to progressively enabling strict mode. Which will benefit from having a plan on how we should tackle the migration. Each category of files should have a proper example how how they should be migrated. And during the initial migration period a best effort should be made to be strict-compliant, but we should not prevent people from adding new files that are not strict. What we should prevent is people adding new non-strict files in the category that we are currently migrating.
Enable the plugin and run
update-strict-comments which adds the
//@ts-strict-ignore comment to
all files which produce a strict error.
- Migrate remaining
- Migrate apps. (And forbid anyone from adding new non-strict files)