docs: 翻译遗漏的文档

This commit is contained in:
Zhicheng WANG
2021-02-05 17:59:29 +08:00
parent 497a2bfaf1
commit 9b60ef0392
4 changed files with 221 additions and 9 deletions
@@ -1,12 +1,21 @@
# `tslib` direct dependency migration
# `tslib` 直接依赖项迁移
## What does this migration do?
## 此迁移有什么用?
If you have any libraries within your workspace, this migration will convert `tslib` peer dependencies to direct dependencies for the libraries.
TypeScript uses the `tslib` package to provide common helper functions used in compiled TypeScript code.
The `tslib` version is also updated to `2.0.0` to support TypeScript 3.9.
如果你的工作空间中有任何库,此迁移会将它们对 `tslib` 的平级依赖转换为直接依赖。TypeScript 使用 `tslib` 包来提供 TypeScript 编译后代码中使用的常用辅助函数。`tslib` 版本也更新为 `2.0.0` 以支持 TypeScript 3.9。
Before:
之前:
```json
{
"name": "my-lib",
@@ -20,6 +29,9 @@ Before:
```
After:
之后:
```json
{
"name": "my-lib",
@@ -36,17 +48,26 @@ After:
## Why is this migration necessary?
## 为什么需要进行此迁移?
The [`tslib`](https://github.com/Microsoft/tslib) is a runtime library for Typescript.
The version of this library is bound to the version of the TypeScript compiler used to compile a library.
Peer dependencies do not accurately represent this relationship between the runtime and the compiler.
If `tslib` remained declared as a library peer dependency, it would be possible for some Angular workspaces to get into a state where the workspace could not satisfy `tslib` peer dependency requirements for multiple libraries, resulting in build-time or run-time errors.
[`tslib`](https://github.com/Microsoft/tslib) 是 Typescript 的运行时库。该库的版本绑定到了用于编译库的 TypeScript 编译器的版本。平级依赖不能准确表达此运行时库与编译器之间的这种关系。如果 `tslib` 仍然声明为库对等依赖项,则某些 Angular 工作空间可能会出现工作空间无法满足 `tslib` 平级依赖项要求的状态,从而导致构建期或运行期错误。
As of TypeScript 3.9 (used by Angular v10), `tslib` version of 2.x is required to build new applications.
However, older libraries built with previous version of TypeScript and already published to npm might need `tslib` 1.x.
This migration makes it possible for code depending on incompatible versions of the `tslib` runtime library to remain interoperable.
从 TypeScript 3.9(由 Angular v10 使用)开始,需要 `tslib` 版本 2.x 来构建新的应用程序。但是,使用以前的 TypeScript 版本构建并已发布到 npm 的较早的库可能需要 `tslib` 。这种迁移使依赖于 `tslib` 运行时库的某个不兼容版本的代码可以保持互操作性。
## Do I still need `tslib` as a dependency in my workspace `package.json`?
## 我是否仍需要 `tslib` 作为我的工作区 `package.json` 的依赖项?
Yes.
The `tslib` dependency declared in the `package.json` file of the workspace is used to build applications within this workspace, as well as run unit tests for workspace libraries, and is required.
是。`package.json` 文件中声明的 `tslib` 依赖用于在此工作空间内构建应用程序,以及对工作空间中的库进行运行单元测试,这是必要的。
@@ -1,33 +1,57 @@
# Update `module` and `target` compiler options migration
# 更新 `module` 和 `target` 编译器选项的迁移
## What does this migration do?
## 此迁移有什么作用?
This migration adjusts the [`target`](https://www.typescriptlang.org/v2/en/tsconfig#target) and [`module`](https://www.typescriptlang.org/v2/en/tsconfig#module) settings within the [TypeScript configuration files](guide/typescript-configuration) for the workspace.
The changes to each option vary based on the builder or command that uses the TypeScript configuration file.
Unless otherwise noted, changes are only made if the existing value was not changed since the project was created.
This process helps ensure that intentional changes to the options are kept in place.
TypeScript Configuration File(s) | Changed Property | Existing Value | New Value
------------- | ------------- | ------------- | ------------- | -------------
`<workspace base>/tsconfig.json` | `"module"` | `"esnext"` | `"es2020"`
Used in `browser` builder options (`ng build` for applications) | `"module"` | `"esnext"` | `"es2020"`
Used in `ng-packgr` builder options (`ng build` for libraries) | `"module"` | `"esnext"` | `"es2020"`
Used in `karma` builder options (`ng test` for applications) | `"module"` | `"esnext"` | `"es2020"`
Used in `server` builder options (universal) | `"module"` | `"commonjs"` | _removed_
Used in `server` builder options (universal) | `"target"` | _any_ | `"es2016"`
Used in `protractor` builder options (`ng e2e` for applications) | `"target"` | `"es5"` | `"es2018"`
此迁移将调整工作区的 [TypeScript 配置文件](guide/typescript-configuration)中的 [`target`](https://www.typescriptlang.org/v2/en/tsconfig#target) 和 [`module`](https://www.typescriptlang.org/v2/en/tsconfig#module) 设置。对每个选项的更改根据使用 TypeScript 配置文件的构建器或命令而有所不同。除非另有说明,否则仅当自创建项目以来未更改过现有值的情况下才进行更改。此过程有助于确保对这些选项进行的更改都是符合意图的。
| TypeScript Configuration File(s) | Changed Property | Existing Value | New Value |
| -------------------------------- | ---------------- | -------------- | --------- |
| TypeScript 配置文件 | 属性变更 | 现有值 | 新值 |
| `<workspace base>/tsconfig.json` | `"module"` | `"esnext"` | `"es2020"` |
| Used in `browser` builder options (`ng build` for applications) | `"module"` | `"esnext"` | `"es2020"` |
| 在 `browser` 构建器选项中使用(用于应用程序的 `ng build`)| `"module"` | `"esnext"` | `"es2020"` |
| Used in `ng-packgr` builder options (`ng build` for libraries) | `"module"` | `"esnext"` | `"es2020"` |
| 在 `ng-packgr` 构建器选项中使用(用于库的 `ng build`)| `"module"` | `"esnext"` | `"es2020"` |
| Used in `karma` builder options (`ng test` for applications) | `"module"` | `"esnext"` | `"es2020"` |
| 在 `karma` 器选项中使用(用于应用程序的 `ng test`)| `"module"` | `"esnext"` | `"es2020"` |
| Used in `server` builder options (universal) | `"module"` | `"commonjs"` | *removed* |
| 在 `server` 构建器选项中使用(通用) | `"module"` | `"commonjs"` | *已移除* |
| Used in `server` builder options (universal) | `"target"` | *any* | `"es2016"` |
| 在 `server` 构建器选项中使用(通用) | `"target"` | *任何* | `"es2016"` |
| Used in `protractor` builder options (`ng e2e` for applications) | `"target"` | `"es5"` | `"es2018"` |
| 在 `protractor` 构建器选项中使用(用于应用程序的 `ng e2e`)| `"target"` | `"es5"` | `"es2018"` |
## Why is this migration necessary?
## 为什么需要此迁移?
This migration provides improvements to the long-term supportability of projects by updating the projects to use recommended best practice compilation options.
此迁移通过更新项目,让它使用建议的最佳实践编译选项,来改善项目的长期支持能力。
For the functionality that executes on Node.js, such as Universal and Protractor, the new settings provide performance and troubleshooting benefits as well.
The minimum Node.js version for the Angular CLI (v10.13) supports features in ES2018 and earlier.
By targeting later ES versions, the compiler transforms less code and can use newer features directly.
Since zone.js does not support native `async` and `await`, the universal builds still target ES2016.
对于要在 Node.js 上执行的功能(例如 Universal 和 Protractor),新设置还提供了性能和故障排除方面的优势。Angular CLI 的最低 Node.js 版本(v10.13)支持 ES2018 及更早版本中的功能。通过瞄准更高版本的 ES,编译器可以转换更少的代码,并且可以直接使用新特性。由于 zone.js 不支持原生 `async` 和 `await` ,因此通用版本仍以 ES2016 为目标。
## Why `"es2020"` instead of `"esnext"`?
## 为什么用 `"es2020"` 代替 `"esnext"` ?
In TypeScript 3.9, the behavior of the TypeScript compiler controlled by `module` is the same with both `"esnext"` and `"es2020"` values.
This behavior can change in the future, because the `"esnext"` option could evolve in a backwards incompatible ways, resulting in build-time or run-time errors during a TypeScript update.
As a result, code can become unstable. Using the `"es2020"` option mitigates this risk.
在 TypeScript 3.9 中,由 `module` 控制的 TypeScript 编译器的行为与 `"esnext"` 和 `"es2020"` 值相同。此行为将来可能会更改,因为 `"esnext"` 选项可能会以向后不兼容的方式发展,从而导致在 TypeScript 更新时导致构建期或运行期错误。其后果是,代码可能变得不稳定。使用 `"es2020"` 选项可减轻此风险。
@@ -1,61 +1,98 @@
# Template expression operators
# 模板表达式运算符
<div class="callout is-critical">
<header>Marked for archiving</header>
<header>已标记为归档</header>
To ensure that you have the best experience possible, this topic is marked for archiving until we determine that it clearly conveys the most accurate information possible.
为确保你拥有最佳的体验,本主题已标记为存档,直到我们确定其清楚地传达了最准确的信息为止。
In the meantime, this topic might be helpful: [Hierarchical injectors](guide/hierarchical-dependency-injection).
同时,下列主题可能会有所帮助:[分层注入器](guide/hierarchical-dependency-injection)。
If you think this content should not be archived, please file a [GitHub issue](https://github.com/angular/angular/issues/new?template=3-docs-bug.md).
如果你认为不应将此内容存档,请提交 [GitHub 问题](https://github.com/angular/angular/issues/new?template=3-docs-bug.md)。
</div>
The Angular template expression language employs a subset of JavaScript syntax supplemented with a few special operators
for specific scenarios.
Angular 模板表达语言采用了 JavaScript 语法的子集,并为特定情况添加了一些特殊的运算符。
<div class="alert is-helpful">
See the <live-example></live-example> for a working example containing the code snippets in this guide.
有关包含本指南中代码片段的有效示例,请参见<live-example></live-example>
</div>
{@a non-null-assertion-operator}
## The non-null assertion operator ( `!` )
## 非空断言运算符( `!` )
When you use TypeScript's `--strictNullChecks` flag, you can prevent the type checker from throwing an error with Angular's non-null assertion operator, `!`.
使用 TypeScript 的 `--strictNullChecks` 标志时,可以防止类型检查器使用 Angular 的非空断言运算符 `!` 。
The Angular non-null assertion operator causes the TypeScript type checker to suspend strict `null` and `undefined` checks for a specific property expression.
Angular 非空断言运算符使 TypeScript 类型检查器暂停对特定属性表达式的 `null` 和 `undefined` 的严格检查。
For example, you can assert that `item` properties are also defined.
例如,你可以断言 `item` 也是已定义的。
<code-example path="template-expression-operators/src/app/app.component.html" region="non-null" header="src/app/app.component.html"></code-example>
Often, you want to make sure that any property bindings aren't `null` or `undefined`.
However, there are situations in which such states are acceptable.
For those situations, you can use Angular's non-null assertion operator to prevent TypeScript from reporting that a property is `null` or `undefined`.
通常,你要确保任何属性绑定都不为 `null` 或 `undefined` 。但是,在某些情况下,这种状态是可以接受的。对于这些情况,可以使用 Angular 的非空断言运算符来防止 TypeScript 报告某个属性为 `null` 或 `undefined`。
The non-null assertion operator, `!`, is optional unless you turn on strict null checks.
非空断言运算符 `!` 是可选的,除非你要启用严格的空检查。
For more information, see TypeScript's [strict null checking](http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html "Strict null checking in TypeScript").
有关更多信息,请参见 TypeScript 的[严格空检查](http://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html "TypeScript 中严格的 null 检查")。
{@a any-type-cast-function}
## The `$any()` type cast function
## `$any()` 类型转换函数
Sometimes a binding expression triggers a type error during [AOT compilation](guide/aot-compiler) and it is not possible or difficult to fully specify the type.
To silence the error, you can use the `$any()` cast function to cast
the expression to the [`any` type](https://www.typescriptlang.org/docs/handbook/basic-types.html#any) as in the following example:
有时,绑定表达式会在 [AOT 编译](guide/aot-compiler)期间触发类型错误,并且不可能或很难完全指定类型。要使此错误静音,可以使用 `$any()` 强制转换函数把表达式强制转换为 [`any` 类型](https://www.typescriptlang.org/docs/handbook/basic-types.html#any),如下例所示:
<code-example path="built-in-template-functions/src/app/app.component.html" region="any-type-cast-function-1" header="src/app/app.component.html"></code-example>
Using `$any()` prevents TypeScript from reporting that `bestByDate` is not a member of the `item` object.
使用 `$any()` 可以防止 TypeScript 报告 `bestByDate` 不是 `item` 对象成员的错误。
The `$any()` cast function also works with `this` to allow access to undeclared members of the component.
`$any()` 强制转换函数也可以与 `this` 一起使用,以允许访问组件的未声明成员。
<code-example path="built-in-template-functions/src/app/app.component.html" region="any-type-cast-function-2" header="src/app/app.component.html"></code-example>
The `$any()` cast function works anywhere in a binding expression where a method call is valid.
`$any()` 强制转换函数可在绑定表达式中任何进行方法调用的地方使用。
File diff suppressed because it is too large Load Diff