From f26819543dd8565c3ff77f1f1969d5f00443de4e Mon Sep 17 00:00:00 2001 From: jaywcjlove Date: Tue, 15 Nov 2022 00:54:34 +0000 Subject: [PATCH] doc: update typescript.md (#69) * feat: update typescript * update c4398d52203e5d7235bc04d4de66a7a4a2a55445 --- CONTRIBUTORS.svg | 18 ++++++++---------- docs/typescript.html | 18 +++++++++++++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTORS.svg b/CONTRIBUTORS.svg index 94128974..f7345966 100644 --- a/CONTRIBUTORS.svg +++ b/CONTRIBUTORS.svg @@ -14,23 +14,21 @@ - - - + - + - + - + - + - + - + - + \ No newline at end of file diff --git a/docs/typescript.html b/docs/typescript.html index 43b8b9fd..cb85d3a2 100644 --- a/docs/typescript.html +++ b/docs/typescript.html @@ -42,7 +42,7 @@

包含最重要基础、泛型、方法、class 等 TypeScript 强类型编程语言语法的快速参考备忘单。初学者的完整快速参考。

入门 Interface

+

入门 Interface

介绍

TypeScript 是具有类型语法的 JavaScript。Interface 是为了匹配它们的运行时行为而构建的。

    @@ -974,8 +974,20 @@ const Form = () => <Select<string> items={['a', 'b']} />;

各种各样的技巧

-

keyof 取 interface 的键

- +

类型推导(infer)

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

keyof 取 interface 的键

interface Point {
     x: number;
     y: number;