Recently in my application I had to enable all of these compiler options:
"alwaysStrict": true,
"extendedDiagnostics": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny", true,
"noImplicitThis", true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true
They are for more stricted compilation, i.e. more secure and I believe they help to achieve code with higher quality. My question is why all of them are by default disabled. According to: https://www.typescriptlang.org/docs/handbook/compiler-options.html
You can already save a lot of typing by simply adding strict: true
. It includes following compiler settings:
--noImplicitAny
--noImplicitThis
--alwaysStrict
--strictBindCallApply
--strictNullChecks
--strictFunctionTypes
--strictPropertyInitialization
strict
is disabled by default. I suppose, that eases up incremental migration from JS projects to TypeScript and doesn't cause too much frustration in the beginning.
extendedDiagnostics
As it outputs verbose diagnostic information for debugging purposes, it's probably not justified as default setting.
noFallthroughCasesInSwitch
depends on your coding style. There are also some valid cases for combined cases.
noImplicitReturns
has been classified as stylistic matter. It doesn't affect type safety, as the compiler can infer return types without you having to declare them explicitely.
noUnusedLocals/Parameters
TypeScript has functionality/IDE support to let editors like VS Code display unused locals and parameters as unused suggestions with separate formatting. So you get the hints without being affected by too much compile erros, e.g. when noEmitOnError: true
.