Type Challenges Judge

IsUnion

提出詳細

type IsNever<T> = T[] extends never[] ? true : false type IsUnion<T, U = T> = IsNever<T> extends true ? false : T extends T ? [U] extends [T] ? false : true : never
提出日時2023-08-09 17:40:42
問題IsUnion
ユーザーookkoouu
ステータス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 >>, ]