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 22, 2023
1 parent b22c815 commit 9fc8523
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,21 @@ type Age2 = Person["age"];
// type Age2 = number
```

### 范型推导出列表字面量
<!--rehype:wrap-class=col-span-2-->

```ts
const a = <T extends string>(t: T) => t;
const b = <T extends number>(t: T) => t;
const c = <T extends boolean>(t: T) => t;
const d = a("a"); // const d: 'a'
const e = a(1); // const d: 1
const f = a(true); // const d: true

const g = <T extends string[]>(t: [...T]) => t; // 这里t的类型用了一个展开运算
const h = g(["111", "222"]); // 类型变成["111", "222"]了
```

.d.ts 模版
---

Expand Down

0 comments on commit 9fc8523

Please sign in to comment.