We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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):
--strict
--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,
--strict --noImplicitThis false
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 by tsc --init to include a "strict": true setting in the "compilerOptions" section. Thus, new projects started with tsc --init will by default have the highest level of type safety enabled.
tsconfig.json
tsc --init
"strict": true
"compilerOptions"
Sorry, something went wrong.
Introduce --strict compiler option
cda741d
Merge branch 'master' into strictChecks
a4e80b5
Accept new tsconfig baselines
7ed13d0
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This sort of thing is a bug waiting to happen - it is very likely that next time someone will need to check a flag like noImplicitAny, they will go through compilerOptions first. That said, I'm not sure what else we could do here.
noImplicitAny
compilerOptions
Doesn't look like this is an accurate statement.
Fixed.
👍 with chaining the default of --init to true.
--init
Change 'tsc --init' to default to 'strict: true'
d3b7058
Accept new baselines
de120b3
f7242f3
Question, why isn't noImplicitReturns part of the strict mode? or others - noUnusedLocals, noFallthroughCasesInSwitch seem also like something I'd expect in strict mode
noImplicitReturns
noUnusedLocals
noFallthroughCasesInSwitch
strict
We had a discussion about this, and these checks along with --noUnusedLocals and --noUnusedParameters seemed "style" options and not "type checking" options. that is why the flag description stresses the "type checks" part.
--noUnusedLocals
--noUnusedParameters
Do you think it's worth putting all the flags that fit in with the group @zaggino mentioned in a separate flag ("strictStyle", or whatever makes sense to call it) or as an optional argument to the strict flag?
The reasoning makes sense to me, but I was surprised to see in today's release notes that those weren't all included; this flag would have been much more useful to me if it did include all that and I could use it as a way to automatically track every strictness-related compiler option going forward.
I do ont think so. style checks are by definition subjective. so not every one would agree on the value of enabling one of them. for example the TS code base heavily relies on implicit returns, and fallthroughs, we do not see these as problems.
Is there a Visual Studio compiler flag for --strict? I found msbuild options but it doesn't mention the --strict option.
<TypeScriptStrict>true</TypeScriptStrict>
Add --strict compiler option in msbuild
4a9d8fb
The `--strict` flag was added in microsoft/TypeScript#14486
DanielRosenwasser DanielRosenwasser requested changes
mhegazy mhegazy approved these changes
Successfully merging this pull request may close these issues.