With the release of Angular 10 a more strict project setup is available. You can enable this by adding a –strict flag when creating a new Angular project:
ng new --strict
This strict mode allows to have more build-time optimizations, help to catch bugs faster and improves overall maintainability of your Angular application.
Therefore it applies the following changes:
- Enables strict mode in TypeScript
- Turns template type checking to Strict
- Default bundle budgets have been reduced by ~75%
- Configures linting rules to prevent declarations of type
any
- Configures your app as side-effect free to enable more advanced tree-shaking
There is no out-of-the box option to enable this for an existing project(after creating it without the –strict flag or after upgrading from a previous version) but you can apply the same changes manually:
Add the following rules to your tsconfig.json
:
"compilerOptions": { "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true }, "angularCompilerOptions": { "strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true }
- Update the
tslint.json:
"no-any": true
- Update the bundle budget sizes in your
angular.json
:
"configurations": { "production": { "budgets": [ { "type": "initial", "maximumWarning": "500kb", "maximumError": "1mb", }, { "type": "anyComponentStyle", "maximumWarning": "2kb", "maximumError": "4kb", }, ] } }
- Add a schematics to your
projects.[projectName].schematics
path in theangular.json
:
schematics: {
"@schematics/angular:application": {
"strict": true
}
}
More information: https://blog.angular.io/angular-cli-strict-mode-c94ba5965f63