Skip to content

Commit 36a9e5e

Browse files
authored
Merge pull request xcatliu#28 from zenghongtu/master
fix: 去除了tuple中一些现版本不支持的内容
2 parents d500c22 + aa8cc18 commit 36a9e5e

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

advanced/tuple.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ xcatliu[1] = 25;
5555

5656
## 越界的元素
5757

58-
当赋值给越界的元素时,它类型会被限制为元组中每个类型的联合类型:
59-
60-
```ts
61-
let xcatliu: [string, number];
62-
xcatliu = ['Xcat Liu', 25, 'http://xcatliu.com/'];
63-
```
64-
65-
上面的例子中,数组的第三项满足联合类型 `string | number`
58+
当添加越界的元素时,它的类型会被限制为元组中每个类型的联合类型:
6659

6760
```ts
6861
let xcatliu: [string, number];
@@ -74,18 +67,6 @@ xcatliu.push(true);
7467
// Type 'boolean' is not assignable to type 'number'.
7568
```
7669

77-
当访问一个越界的元素,也会识别为元组中每个类型的联合类型:
78-
79-
```ts
80-
let xcatliu: [string, number];
81-
xcatliu = ['Xcat Liu', 25, 'http://xcatliu.com/'];
82-
83-
console.log(xcatliu[2].slice(1));
84-
85-
// index.ts(4,24): error TS2339: Property 'slice' does not exist on type 'string | number'.
86-
```
87-
88-
之前提到过,[如果一个值是联合类型,我们只能访问此联合类型的所有类型里共有的属性或方法。](../basics/union-types.md#访问联合类型的属性或方法)
8970

9071
## 参考
9172

advanced/type-aliases.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ type NameOrResolver = Name | NameResolver;
1111
function getName(n: NameOrResolver): Name {
1212
if (typeof n === 'string') {
1313
return n;
14-
}
15-
else {
14+
} else {
1615
return n();
1716
}
1817
}

0 commit comments

Comments
 (0)