Skip to content

Commit fba72f0

Browse files
jbogarthydeAndrewKushnir
authored andcommitted
docs: rewrite ivy page, add template typecheck doc (angular#33152)
PR Close angular#33152
1 parent 5666d11 commit fba72f0

5 files changed

Lines changed: 93 additions & 48 deletions

File tree

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@
471471
/aio/content/guide/web-worker.md @angular/tools-cli @angular/framework-global-approvers @angular/framework-global-approvers-for-docs-only-changes
472472

473473

474-
475474
# ================================================
476475
# @angular/core
477476
# @angular/common (except @angular/common/http)

aio/content/guide/aot-compiler.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,10 +564,25 @@ It does not, however, rewrite the `.d.ts` file, so TypeScript doesn't recognize
564564
{@a binding-expression-validation}
565565
## Phase 3: Template type checking
566566
567+
One of the Angular compiler's most helpful features is the ability to type-check expressions within templates, and catch any errors before they cause crashes at runtime.
567568
In the template type-checking phase, the Angular template compiler uses the TypeScript compiler to validate the binding expressions in templates.
569+
568570
Enable this phase explicitly by adding the compiler option `"fullTemplateTypeCheck"` in the `"angularCompilerOptions"` of the project's `tsconfig.json`
569571
(see [Angular Compiler Options](guide/angular-compiler-options)).
570572
573+
<div class="alert is-helpful>
574+
575+
In [Angular Ivy](guide/ivy), the template type checker has been completely rewritten to be more capable as well as stricter, meaning it can catch a variety of new errors that the previous type checker would not detect.
576+
577+
As a result, templates that previously compiled under View Engine can fail type checking under Ivy. This can happen because Ivy's stricter checking catches genuine errors, or because application code is not typed correctly, or because the application uses libraries in which typings are inaccurate or not specific enough.
578+
579+
This stricter type checking is not enabled by default in version 9, but can be enabled by setting the `strictTemplates` configuration option.
580+
We do expect to make strict type checking the default in the future.
581+
582+
<!-- For more information about type-checking options, and about improvements to template type checking in version 9 and above, see [Template type checking](guide/template-type-checking). -->
583+
584+
</div>
585+
571586
Template validation produces error messages when a type error is detected in a template binding
572587
expression, similar to how type errors are reported by the TypeScript compiler against code in a `.ts`
573588
file.

aio/content/guide/ivy-compatibility.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
# Ivy Compatibility Guide
22

3-
The Angular team has worked hard to ensure Ivy is as backwards-compatible with the previous rendering engine ("View Engine") as possible.
3+
The Angular team has worked hard to ensure Ivy is as backwards-compatible with the previous rendering engine ("View Engine") as possible.
44
However, in rare cases, minor changes were necessary to ensure that the Angular's behavior was predictable and consistent, correcting issues in the View Engine implementation.
55
In order to smooth the transition, we have provided automated migrations wherever possible so your application and library code is migrated automatically by the CLI.
66
That said, some applications will likely need to apply some manual updates.
77

88
{@a debugging}
99
## How to Debug Errors with Ivy
1010

11-
In version 9, [a few deprecated APIs have been removed](guide/updating-to-version-9#removals) and there are a [few breaking changes](guide/updating-to-version-9#breaking-changes) unrelated to Ivy.
12-
If you're seeing errors after updating to version 9, you'll first want to rule those changes out.
11+
In version 9, [a few deprecated APIs have been removed](guide/updating-to-version-9#removals) and there are a [few breaking changes](guide/updating-to-version-9#breaking-changes) unrelated to Ivy.
12+
If you're seeing errors after updating to version 9, you'll first want to rule those changes out.
1313

1414
To do so, temporarily [turn off Ivy in your `tsconfig.json`](guide/ivy#opting-out-of-angular-ivy) and re-start your app.
1515

1616
If you're still seeing the errors, they are not specific to Ivy. In this case, you may want to consult the [general version 9 guide](guide/updating-to-version-9).
17-
18-
If the errors are gone, switch back to Ivy by removing the changes to the `tsconfig.json` and review the list of expected changes below.
17+
18+
If the errors are gone, switch back to Ivy by removing the changes to the `tsconfig.json` and review the list of expected changes below.
1919

2020

2121
{@a common-changes}
2222
## Changes You May See
2323

24-
Below are a few breaking changes that are more likely than others to be visible as applications are transitioning to Ivy.
24+
Below are a few breaking changes that are more likely than others to be visible as applications are transitioning to Ivy.
2525

26-
- By default, `@ContentChildren` queries will only search direct child nodes in the DOM hierarchy (previously, they would search any nesting level in the DOM as long as another directive wasn't matched above it).
26+
- By default, `@ContentChildren` queries will only search direct child nodes in the DOM hierarchy (previously, they would search any nesting level in the DOM as long as another directive wasn't matched above it).
2727

2828
- All classes that use Angular DI must have an Angular decorator like `@Directive()` or `@Injectable` (previously, undecorated classes were allowed if an ancestor class or subclass had a decorator).
2929

@@ -33,17 +33,17 @@ Below are a few breaking changes that are more likely than others to be visible
3333
{@a less-common-changes}
3434
## Less Common Changes
3535

36-
The following changes will be visible more rarely, as they mostly deal in edge cases or unspecified behavior that is not part of our public API.
36+
The following changes will be visible more rarely, as they mostly deal in edge cases or unspecified behavior that is not part of our public API.
3737

3838
- Properties like `host` inside `@Component` and `@Directive` decorators can be inherited (previously, only properties with explicit field decorators like `@HostBinding` would be inherited).
3939

4040
- HammerJS support is opt-in through importing the `HammerModule` (previously, it was always included in production bundles regardless of whether the app used HammerJS).
4141

4242
- `@ContentChild` and `@ContentChildren` queries will no longer be able to match their directive's own host node (previously, these queries would match the host node in addition to its content children).
4343

44-
- If a token is injected with the `@Host` or `@Self` flag, the module injector is not searched for that token (previously, tokens marked with these flags would still search at the module level).
44+
- If a token is injected with the `@Host` or `@Self` flag, the module injector is not searched for that token (previously, tokens marked with these flags would still search at the module level).
4545

46-
- If a template is declared in one view but inserted into a different view, change detection will occur for that template only when its insertion point is checked (previously, change detection would also run when its declaration point was checked).
46+
- If a template is declared in one view but inserted into a different view, change detection will occur for that template only when its insertion point is checked (previously, change detection would also run when its declaration point was checked).
4747

4848
- When accessing multiple local refs with the same name in template bindings, the first is matched (previously, the last instance was matched).
4949

@@ -57,7 +57,7 @@ The following changes will be visible more rarely, as they mostly deal in edge c
5757

5858
- It is now an error to assign values to template-only variables like `item` in `ngFor="let item of items"` (previously, the compiler would ignore these assignments).
5959

60-
- It's no longer possible to overwrite lifecycle hooks with mocks on directive instances for testing (instead, modify the lifecycle hook on the directive type itself).
60+
- It's no longer possible to overwrite lifecycle hooks with mocks on directive instances for testing (instead, modify the lifecycle hook on the directive type itself).
6161

6262
- Special injection tokens (e.g. `TemplateRef` or `ViewContainerRef`) return a new instance whenever they are requested (previously, instances of special tokens were shared if requested on the same node). This primarily affects tests that do identity comparison of these objects.
6363

aio/content/guide/ivy.md

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,31 @@
1-
# Opting out of Angular Ivy
1+
# Angular Ivy
22

3-
Ivy is the code name for Angular's [next-generation compilation and rendering pipeline](https://blog.angular.io/a-plan-for-version-8-0-and-ivy-b3318dfc19f7).
4-
Starting with Angular version 9, Ivy compilation and rendering pipeline is enabled by default.
5-
The previous compilation and rendering pipeline, View Engine, is deprecated in version 9, and will be removed at a later date.
6-
You can choose to opt out of Ivy and continue using View Engine while making the transition.
3+
Ivy is the code name for Angular's [next-generation compilation and rendering pipeline](https://blog.angular.io/a-plan-for-version-8-0-and-ivy-b3318dfc19f7).
4+
With the version 9 release of Angular, the new compiler and runtime instructions are used by default instead of the older compiler and runtime, known as View Engine.
5+
6+
<div class="alert is-helpful">
7+
8+
Learn more about the [Compiler](https://www.youtube.com/watch?v=anphffaCZrQ) and [Runtime](https://www.youtube.com/watch?v=S0o-4yc2n-8) in these videos from our team.
79

8-
To opt out of Ivy and continue using View Engine for an existing project, set the `enableIvy` option in the `angularCompilerOptions` in your project's `tsconfig.json` to `false`.
9-
<code-example language="json" header="tsconfig.json">
10-
{
11-
"compilerOptions": { ... },
12-
"angularCompilerOptions": {
13-
"enableIvy": false
14-
}
15-
}
16-
</code-example>
1710

18-
AOT compilation with Ivy is faster than with View Engine, and can be used for development.
19-
If you opt out of Ivy, AOT compilation will be slower, and should not be used for development in large projects.
20-
When Ivy is disabled for a large project, make sure that the `aot` build option in that project configuration is
21-
set to `false` and it's only set to `true` in the `production` configuration.
11+
</div>
12+
13+
{@a aot-and-ivy}
14+
## AOT and Ivy
15+
16+
AOT compilation with Ivy is faster and should be used by default.
17+
In the `angular.json` workspace configuration file, set the default build options for your project to always use AOT compilation.
2218

2319
<code-example language="json" header="angular.json">
20+
2421
{
2522
"projects": {
2623
"my-existing-project": {
2724
"architect": {
2825
"build": {
2926
"options": {
3027
...
31-
"aot": false,
32-
},
33-
"configurations": {
34-
"production": {
35-
...
36-
"aot": true
37-
}
28+
"aot": true,
3829
}
3930
}
4031
}
@@ -43,13 +34,53 @@ set to `false` and it's only set to `true` in the `production` configuration.
4334
}
4435
</code-example>
4536

46-
Ivy projects usually contain a `postinstall` script in the `scripts` section of `package.json` that converts packages in `node_modules` to use Ivy as well.
47-
When you opt out of Ivy, remove this script. Remove the following line in package.json.
37+
## Ivy and libraries
38+
39+
Ivy applications can be built with libraries that were created with the View Engine compiler.
40+
This compatibility is provided by a tool known as the Angular compatibility compiler (`ngcc`).
41+
CLI commands run `ngcc` as needed, either after npm installation of dependencies or when performing an Angular build.
42+
43+
If you are a library author, you should keep using the View Engine compiler as of version 9.
44+
By having all libraries continue to use View Engine, you will maintain compatibility with default v9 applications that use Ivy, as well as with applications that have opted to continue using View Engine.
4845

49-
<code-example language="json" header="package.json">
46+
See the [Creating Libraries](guide/creating-libraries) guide for more on how to compile or bundle your Angular library.
47+
When you use the tools integrated into the Angular CLI or `ng-packagr`, your library will always be built the right way automatically.
48+
49+
{@a opting-out-of-angular-ivy}
50+
## Opting out of Ivy in version 9
51+
52+
In version 9, Ivy is the default.
53+
For compatibility with current workflows during the update process, you can choose to opt out of Ivy and continue using the previous compiler, View Engine.
54+
55+
<div class="alert is-helpful>
56+
57+
Before disabling Ivy, check out the debugging recommendations in the [Ivy Compatibility Guide](guide/ivy-compatibility#debugging).
58+
59+
</div>
60+
61+
To opt out of Ivy, change the `angularCompilerOptions` in your project's TypeScript configuration, most commonly located at `tsconfig.app.json` at the root of the workspace.
62+
63+
The value of the `enableIvy` flag is set to `true` by default, as of version 9.
64+
The following example shows how to set the `enableIvy` option to `false` in order to opt out of Ivy.
65+
66+
<code-example language="json" header="tsconfig.app.json">
5067
{
51-
"scripts": {
52-
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points"
53-
}
68+
"extends": "./tsconfig.json",
69+
"compilerOptions": {
70+
"outDir": "./out-tsc/app",
71+
"types": []
72+
},
73+
"include": [
74+
"src/**/*.ts"
75+
],
76+
"exclude": [
77+
"src/test.ts",
78+
"src/**/*.spec.ts"
79+
],
80+
"angularCompilerOptions": {
81+
"enableIvy": false
82+
}
5483
}
5584
</code-example>
85+
86+
If you disable Ivy, you might also want to reconsider whether to make AOT compilation the default for your application development, as described [above](#aot-and-ivy). To revert the compiler default, set the build option `aot: false` in the `angular.json` configuration file.

aio/content/navigation.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,6 @@
576576
"title": "CLI Builders",
577577
"tooltip": "Using builders to customize Angular CLI."
578578
},
579-
{
580-
"url": "guide/ivy",
581-
"title": "Angular Ivy",
582-
"tooltip": "Opting out of Angular Ivy with Angular CLI."
583-
},
584579
{
585580
"url": "guide/web-worker",
586581
"title": "Web Workers",
@@ -712,6 +707,11 @@
712707
"url": "guide/deprecations",
713708
"title": "Deprecations",
714709
"tooltip": "Summary of Angular APIs and features that are deprecated."
710+
},
711+
{
712+
"url": "guide/ivy",
713+
"title": "Angular Ivy",
714+
"tooltip": "About the Angular Ivy compilation and rendering pipeline."
715715
}
716716
]
717717
},

0 commit comments

Comments
 (0)