In Angular, we strongly believe in consistency and best practices. For example, we adopted TypeScript in its early days because we wanted all developers using the framework to take advantage of compile-time type checking. This way, we enabled an excellent development experience for everyone with better editor support, allowing people to ship apps with fewer issues.

In Angular v10 we announced a strict opt-in mode that allows us to perform more build-time optimizations and help you deliver faster apps with fewer defects. This mode is still only an opt-in because it comes with its trade-offs — stricter type checking and extra configuration. We want to hear from you which of these trade-offs will make you more productive and allow you to deliver better apps.

Image for post

Opting in to Strict Mode

To opt into the strict mode, you need to create a new Angular CLI app, specifying the --strict flag:

ng new my-app --strict

The command above will generate a workspace with the following settings enabled on top of the defaults:

  • Strict mode in TypeScript, as well as other strictness flags recommended by the TypeScript team. Specifically, strict, forceConsistentCasingInFileNames, noImplicitReturns, noFallthroughCasesInSwitch
  • Turns on strict Angular compiler flags strictTemplates and strictInjectionParameters
  • Reduced bundle size budgets by ~75%
  • Turns on no-any TSLint rule to prevent declarations of type any
  • Marks your application as side-effect free to enable more advanced tree-shaking

Let us look at each one of these in detail.

#web-development #angular #typescript #javascript

Angular CLI Strict Mode
8.80 GEEK