File tree Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Expand file tree Collapse file tree 1 file changed +3
-4
lines changed Original file line number Diff line number Diff line change @@ -742,7 +742,7 @@ if (true) {
742
742
743
743
## 类型的兼容
744
744
745
- TypeScript 的类型存在兼容关系,某些类可以兼容其他类 。
745
+ TypeScript 的类型存在兼容关系,某些类型可以兼容其他类型 。
746
746
747
747
``` typescript
748
748
type T = number | string ;
@@ -751,10 +751,9 @@ let a:number = 1;
751
751
let b: T = a ;
752
752
```
753
753
754
- 上面示例中,变量` a ` 和` b ` 的类型是不一样的,但是变量` a ` 赋值给变量` b ` 并不会报错。这时,我们就认为,变量 ` b ` 兼容变量 ` a ` 。
754
+ 上面示例中,变量` a ` 和` b ` 的类型是不一样的,但是变量` a ` 赋值给变量` b ` 并不会报错。这时,我们就认为,` b ` 的类型兼容 ` a ` 的类型 。
755
755
756
- TypeScript
757
- 为这种情况定义了一个专门术语。如果类型` A ` 的值可以赋值给类型` B ` ,那么类型` A ` 就称为类型` B ` 的子类型(subtype)。在上例中,类型` number ` 就是类型` number|string ` 的子类型。
756
+ TypeScript 为这种情况定义了一个专门术语。如果类型` A ` 的值可以赋值给类型` B ` ,那么类型` A ` 就称为类型` B ` 的子类型(subtype)。在上例中,类型` number ` 就是类型` number|string ` 的子类型。
758
757
759
758
TypeScript 的一个规则是,凡是可以使用父类型的地方,都可以使用子类型,但是反过来不行。
760
759
You can’t perform that action at this time.
0 commit comments