diff --git a/docs/typescript.html b/docs/typescript.html index b0c18234..92de7cca 100644 --- a/docs/typescript.html +++ b/docs/typescript.html @@ -42,7 +42,7 @@

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

入门 Interface

介绍

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

    @@ -973,6 +973,35 @@ // 使用 const Form = () => <Select<string> items={['a', 'b']} />; +

各种各样的技巧

+

keyof 取 interface 的键

+ +
interface Point {
+    x: number;
+    y: number;
+}
+ 
+// type keys = "x" | "y"
+type keys = keyof Point;
+
+

索引签名

+
interface NumberOrString {
+  [index: string]: string | number;
+  length: number;
+  name: string;
+}
+
+

从数组中提取类型

+
type Point = { x: number; y: number; }
+type Data = Point[];
+// Data 是个数组,提取里面的元素类型
+type PointDetail = Data[number];
+// type PointDetail = { x: number; y: number; }
+
+

只读元组类型

+
const point = [3, 4] as const
+// type 'readonly [3, 4]'
+