From c4398d52203e5d7235bc04d4de66a7a4a2a55445 Mon Sep 17 00:00:00 2001 From: fw_qaq <82551626+Jack-Zhang-1314@users.noreply.github.com> Date: Tue, 15 Nov 2022 08:53:28 +0800 Subject: [PATCH] doc: update typescript.md (#69) * feat: update typescript * update --- docs/typescript.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/typescript.md b/docs/typescript.md index da75fb3f8fe..9b92752e476 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -1268,8 +1268,24 @@ const Form = () => items={['a', 'b']} />; 各种各样的技巧 --- +### 类型推导(infer) + + +```ts +type Capitalize = T extends `${infer U}${infer V}` + ? `${Uppercase}${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 的键 - ```ts interface Point {