From 9fc8523762131deb5952ac1d9f9f61b9728612be Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sun, 23 Jul 2023 00:19:37 +0800 Subject: [PATCH] doc: update docs/typescript.md --- docs/typescript.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/typescript.md b/docs/typescript.md index 8ba6d56..dabc3f7 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -1503,6 +1503,21 @@ type Age2 = Person["age"]; // type Age2 = number ``` +### 范型推导出列表字面量 + + +```ts +const a = (t: T) => t; +const b = (t: T) => t; +const c = (t: T) => t; +const d = a("a"); // const d: 'a' +const e = a(1); // const d: 1 +const f = a(true); // const d: true + +const g = (t: [...T]) => t; // 这里t的类型用了一个展开运算 +const h = g(["111", "222"]); // 类型变成["111", "222"]了 +``` + .d.ts 模版 ---