doc: update typescript.md (#69)

* feat: update typescript

* update
This commit is contained in:
fw_qaq 2022-11-15 08:53:28 +08:00 committed by GitHub
parent ada64ac643
commit c4398d5220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {