From 72f731f3f982dccd4d76e042e0d3c5df213956d0 Mon Sep 17 00:00:00 2001 From: zhouzhenpan Date: Mon, 29 Jul 2024 10:05:34 +0800 Subject: [PATCH] feat: without --- src/05117-medium-without.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/05117-medium-without.ts diff --git a/src/05117-medium-without.ts b/src/05117-medium-without.ts new file mode 100644 index 0000000..2fcba6a --- /dev/null +++ b/src/05117-medium-without.ts @@ -0,0 +1,25 @@ +// ============= Test Cases ============= +import type { Equal, Expect } from './test-utils' + +type cases = [ + Expect, [2]>>, + Expect, [4, 5]>>, + Expect, []>> +] + +// ============= Your Code Here ============= + +type ArrayToUnion = T extends number[] + ? T[number] + : T + +/** 遇到`U`可能是数组或数字的情况下,把数组转成Union类型,然后使用extends作为条件就很方便处理 */ +type Without< + T, + U extends number | number[], + Result extends any[] = [] +> = T extends [infer F, ...infer R] + ? F extends ArrayToUnion + ? Without + : Without + : Result