Book Image

Accelerating Angular Development with Ivy

By : Lars Gyrup Brink Nielsen, Mateus Carniatto, Jacob Andresen
Book Image

Accelerating Angular Development with Ivy

By: Lars Gyrup Brink Nielsen, Mateus Carniatto, Jacob Andresen

Overview of this book

Angular Ivy is the latest rendering engine and compiler introduced in Angular. Ivy helps frontend developers to make their Angular applications faster, better optimized, and more robust. This easy-to-follow guide will help you get to grips with the new features of Angular Ivy and show you how to migrate your Angular apps from View Engine to Ivy. You'll begin by learning about the most popular features of Angular Ivy with the help of simple stand-alone examples and realize its capabilities by working on a real-world application project. You'll then discover strategies to improve your developer workflow through new debugging APIs, testing APIs, and configurations that support higher code quality and productive development features. Throughout the book, you'll explore essential components of Angular, such as Angular Component Dev Kit (CDK), Ahead-of-time (AOT) compilation, and Angular command line interface (CLI). Finally, you'll gain a clear understanding of these components along with Angular Ivy which will help you update your Angular applications with modern features. By the end of this Angular Ivy book, you will learn about the core features of Angular Ivy, discover how to migrate your Angular View Engine application, and find out how to set up a high-quality Angular Ivy project.
Table of Contents (14 chapters)

Taking advantage of strict mode and other new configurations

Angular has always been big on tooling. Ivy adds and enables additional configurations that help us catch errors early and output smaller bundles.

Strict mode

When we create an Angular workspace using the ng new command, the --strict parameter flag is on by default as of Angular version 12. Using the strict workspace preset enables additional static analysis. The --strict parameter flag is also supported for project generation schematics such as ng generate application and ng generate library.

The strict preset sets the following TypeScript compiler options to true:

  • forceConsistentCasingInFileNames
  • noImplicitReturns
  • noFallthroughCasesInSwitch
  • strict

These options help us catch a lot of potential errors at compile time. Refer to the TypeScript documentation for details about the individual compiler options. The strict TypeScript compiler option is a shorthand for enabling all the following compiler options as of TypeScript version 4.2:

  • alwaysStrict
  • noImplicitAny
  • noImplicitThis
  • strictBindCallApply
  • strictFunctionTypes
  • strictNullChecks
  • strictPropertyInitialization

Additionally, future strict TypeScript compiler options will be enabled automatically when using the strict shorthand.

Bundle budgets are reduced in strict mode. The initial bundle warns at 500 kilobytes (KB) and errs at 1 megabyte (MB), while component styles warn at 2 KB and err at 4 KB.

Strict mode further enables strict template type checking, which we will cover later in this chapter.

Angular compiler options

Only a few Angular compiler option defaults have changed in Ivy. In Angular version 9, the default value of the enableIvy option was set to true for applications but false for libraries. This changed in Angular version 12, where the enableIvy option was removed entirely when View Engine support was disabled for Angular applications and the "partial" value for the compilationMode option was added for partial Ivy compilation of Angular libraries.

The strictTemplates option is introduced with Ivy. Its default value is false, but it is set to true when generating an Angular workspace by using the ng new command, which enables the --strict parameter flag. The same applies to the fullTemplateTypeCheck option, which is implicitly set by the strictTemplates option.

The default value of the strictInjectionParameters and strictInputAccessModifiers options is still false, but it is set to true when generating an Angular workspace by using the ng new command.

Now that you are aware of the many helpful configuration options introduced by Angular Ivy, you can gain more confidence about how your Angular application will behave in production runtime.

Next up is a favorite topic of ours: testing. Both Ivy and its related TypeScript versions introduce substantial improvements to the Angular testing experience.