Skip to content

Commit

Permalink
doc: update typescript.md (jaywcjlove#69)
Browse files Browse the repository at this point in the history
* feat: update typescript

* update
  • Loading branch information
fwqaaq authored Nov 15, 2022
1 parent ada64ac commit c4398d5
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,24 @@ const Form = () => <Select<string> items={['a', 'b']} />;
各种各样的技巧
---

### 类型推导(infer)
<!--rehype:wrap-class=col-span-2-->

```ts
type Capitalize<T extends string> = T extends `${infer U}${infer V}`
? `${Uppercase<U>}${V}`
: T
type capitalized = Capitalize<"hello world"> // Hello World
```
- 也可以在 infer 中使用条件约束(`extends`
```ts
type SomeBigInt = "100" extends `${infer U extends bigint}` ? U : never;
// 100n
```

### keyof 取 interface 的键
<!--rehype:wrap-class=row-span-2-->

```ts
interface Point {
Expand Down

0 comments on commit c4398d5

Please sign in to comment.