Type Challenges Judge

Intersection

提出詳細

type Intersection<T> = T extends [infer T1, ...infer T2] ? T1 extends readonly unknown[] ? T1[number] & Intersection<T2> : T1 & Intersection<T2> : unknown
提出日時2023-09-22 13:07:30
問題Intersection
ユーザーsankantsu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Intersection<[[1, 2], [2, 3], [2, 2]]>, 2>>, Expect<Equal<Intersection<[[1, 2, 3], [2, 3, 4], [2, 2, 3]]>, 2 | 3>>, Expect<Equal<Intersection<[[1, 2], [3, 4], [5, 6]]>, never>>, Expect<Equal<Intersection<[[1, 2, 3], [2, 3, 4], 3]>, 3>>, Expect<Equal<Intersection<[[1, 2, 3], 2 | 3 | 4, 2 | 3]>, 2 | 3>>, Expect<Equal<Intersection<[[1, 2, 3], 2, 3]>, never>>, ]