From 1a37518aabb1569fcd0512b60c5d93961031013b Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Fri, 9 Aug 2024 11:35:26 +0800 Subject: [PATCH] doc: update docs/typescript.md --- docs/typescript.md | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/docs/typescript.md b/docs/typescript.md index 96c06f0..788950a 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -1495,18 +1495,6 @@ function makeBox(value: T) { } ``` -### 保留一段时间字符串常量类型 - -```ts -type Color = "primary" | "secondary" | string; -``` - -修改成下面代码,有代码下拉提示 - -```ts -type Color = "primary" | "secondary" | (string & {}); -``` - --- 不使用: @@ -1563,6 +1551,7 @@ type Age2 = Person["age"]; ``` ### 范型推导出列表字面量 + ```ts const a = (t: T) => t; @@ -1571,11 +1560,18 @@ const c = (t: T) => t; const d = a("a"); // const d: 'a' const e = b(1); // const d: 1 const f = c(true); // const d: true +``` -// 这里t的类型用了一个展开运算 +这里t的类型用了一个展开运算 + +```ts const g = - (t: [...T]) => t; -// 类型变成["111", "222"]了 + (t: [...T]) => t; +``` + +类型变成["111", "222"]了 + +```ts const h = g(["111", "222"]); ``` @@ -1592,6 +1588,19 @@ keys.forEach(key => { }); ``` +### 保留一段时间字符串常量类型 + + +```ts +type Color = "primary" | "secondary" | string; +``` + +修改成下面代码,有代码下拉提示 + +```ts +type Color = "primary" | "secondary" | (string & {}); +``` + .d.ts 模版 ---