Type Challenges Judge

IsUnion

提出詳細

type IsUnion<T, U = T> = T extends any ? [U] extends [T] ? false : true : never
提出日時2023-08-12 08:10:04
問題IsUnion
ユーザーtekihei2317
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<IsUnion<string>, false >>, Expect<Equal<IsUnion<string|number>, true >>, Expect<Equal<IsUnion<'a'|'b'|'c'|'d'>, true >>, Expect<Equal<IsUnion<undefined|null|void|''>, true >>, Expect<Equal<IsUnion<{ a: string }|{ a: number }>, true >>, Expect<Equal<IsUnion<{ a: string|number }>, false >>, Expect<Equal<IsUnion<[string|number]>, false >>, // Cases where T resolves to a non-union type. Expect<Equal<IsUnion<string|never>, false >>, Expect<Equal<IsUnion<string|unknown>, false >>, Expect<Equal<IsUnion<string|any>, false >>, Expect<Equal<IsUnion<string|'a'>, false >>, ]