Skip to content

Commit

Permalink
doc: update docs/typescript.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 17, 2023
1 parent 7841be7 commit 89be124
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,22 @@ type A = keyof Arrayish;
// type A = number
```

### 两个数组合并成一个新类型
<!--rehype:wrap-class=col-span-2 row-span-2-->

```ts
const named = ["aqua", "aquamarine", "azure"] as const;
const hex = ["#00FFFF", "#7FFFD4", "#F0FFFF"] as const;

type Colors = {
[key in (typeof named)[number]]: (typeof hex)[number];
};
// Colors = {
// aqua: "#00FFFF" | "#7FFFD4" | "#F0FFFF";
// ....
// }
```

### 索引签名

```ts
Expand All @@ -1348,6 +1364,13 @@ interface NumberOrString {
}
```

### 只读元组类型

```ts
const point = [3, 4] as const
// type 'readonly [3, 4]'
```

### 从数组中提取类型

```ts
Expand All @@ -1359,15 +1382,8 @@ type PointDetail = Data[number];
```
<!--rehype:className=wrap-text-->

### 只读元组类型

```ts
const point = [3, 4] as const
// type 'readonly [3, 4]'
```

### satisfies
<!--rehype:wrap-class=row-span-2-->
<!--rehype:wrap-class=row-span-3-->

`satisfies` 允许将验证表达式的类型与某种类型匹配,而无需更改该表达式的结果类型。

Expand Down Expand Up @@ -1406,7 +1422,7 @@ const redComponent = palette.red.at(0)
<!--rehype:className=wrap-text-->

### 范型实例化表达式
<!--rehype:wrap-class=row-span-2-->
<!--rehype:wrap-class=row-span-3-->

不使用的情况下:

Expand Down

0 comments on commit 89be124

Please sign in to comment.