IsUnion
提出詳細
type IsUnion<T, U = T> = T extends U ? [U] extends [T] ? false : true : never;
提出日時 | 2024-10-30 01:58:10 |
---|---|
問題 | IsUnion |
ユーザー | balckowl |
ステータス | 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 >>, ]