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 Aug 9, 2024
1 parent 01757ed commit 1a37518
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -1495,18 +1495,6 @@ function makeBox<T>(value: T) {
}
```
### 保留一段时间字符串常量类型
```ts
type Color = "primary" | "secondary" | string;
```
修改成下面代码,有代码下拉提示
```ts
type Color = "primary" | "secondary" | (string & {});
```
---
不使用:
Expand Down Expand Up @@ -1563,6 +1551,7 @@ type Age2 = Person["age"];
```
### 范型推导出列表字面量
<!--rehype:wrap-class=row-span-2-->
```ts
const a = <T extends string>(t: T) => t;
Expand All @@ -1571,11 +1560,18 @@ const c = <T extends boolean>(t: T) => t;
const d = a("a"); // const d: 'a'
const e = b(1); // const d: 1
const f = c(true); // const d: true
```
这里t的类型用了一个展开运算
// 这里t的类型用了一个展开运算
```ts
const g =
<T extends string[]>(t: [...T]) => t;
// 类型变成["111", "222"]了
<T extends string[]>(t: [...T]) => t;
```
类型变成["111", "222"]了
```ts
const h = g(["111", "222"]);
```
Expand All @@ -1592,6 +1588,19 @@ keys.forEach(key => {
});
```
### 保留一段时间字符串常量类型
<!--rehype:wrap-class=col-span-2-->
```ts
type Color = "primary" | "secondary" | string;
```
修改成下面代码,有代码下拉提示
```ts
type Color = "primary" | "secondary" | (string & {});
```
.d.ts 模版
---
Expand Down

0 comments on commit 1a37518

Please sign in to comment.