Description
I would like to make use of the --strictNullChecks
option in an existing TypeScript codebase that is ~25K LOC in size. Not surprisingly, this throws up a substantial number of errors (~640).
It would be very helpful if it was possible to tackle them gradually and keep the codebase compilable the whole time. The need to be able to tackle these issues gradually is especially true for --strictNullChecks
because a reasonable number of the errors that came up are real potential issues that require some thought, rather than problems which can just be fixed in a mechanical fashion.
Ideally what I would like is to be able to suppress checks on a per-file basis, enabling a gradual conversion as follows:
- Enable
--strictNullChecks
for the project - Attempt to compile and add
// @typescript:-strictNullChecks
to each file that produces an error - Pick the first file with such a directive, remove it and fix any errors.
- Repeat step 3 for each file with such a directive
Although it is possible to suppress errors with the !
operator, this could end up hiding real bugs and it would be unclear when the operator was used in the process of migration vs. to suppress an error in a case where it isn't possible to statically prove to the compiler that a value is non-null.