Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR introduces a new
--strict
compiler option that represents the recommended setting of a number of type checking options. Specifically, specifying--strict
corresponds to specifying all of the following options (and may in the future include more options):--strictNullChecks
--noImplicitAny
--noImplicitThis
--alwaysStrict
When we introduce new type checker features in TypeScript we often put them under a compiler switch and leave them off by default in order to avoid breaking existing projects. While avoiding breakage is a good thing, this strategy has the drawback of making it increasingly complex to choose the highest level of type safety, and doing so requires explicit opt-in action on every TypeScript release. With the
--strict
option it becomes possible to choose maximum type safety with the understanding that additional errors might be reported by newer versions of the compiler as improved type checking features are added.In exact terms, the
--strict
option sets the default value for the compiler options listed above. This means it is still possible to individually control the options. For example,has the effect of turning on all strict options except the
--noImplicitThis
option. Using this scheme it is possible to express configurations consisting of all strict options except some explicitly listed options. In other words, it is now possible to default to the highest level of type safety but opt out of certain checks.The PR also modifies the default
tsconfig.json
generated bytsc --init
to include a"strict": true
setting in the"compilerOptions"
section. Thus, new projects started withtsc --init
will by default have the highest level of type safety enabled.