AnyOf
提出詳細
type Truethly<T> = T extends number ? T extends 0 ? false : true : T extends string ? T extends "" ? false : true : T extends boolean ? T : T extends unknown[] ? T["length"] extends 0 ? false : true : T extends object ? T[keyof T] extends [never] ? false : true : never type AnyOf<T extends readonly any[]> = T extends [infer Tgt, ...infer Rest] ? Truethly<Tgt> extends true ? Truethly<Tgt> : AnyOf<Rest> : false
提出日時 | 2024-09-10 08:52:59 |
---|---|
問題 | AnyOf |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<AnyOf<[1, 'test', true, [1], { name: 'test' }, { 1: 'test' }]>, true>>, Expect<Equal<AnyOf<[1, '', false, [], {}]>, true>>, Expect<Equal<AnyOf<[0, 'test', false, [], {}]>, true>>, Expect<Equal<AnyOf<[0, '', true, [], {}]>, true>>, Expect<Equal<AnyOf<[0, '', false, [1], {}]>, true>>, Expect<Equal<AnyOf<[0, '', false, [], { name: 'test' }]>, true>>, Expect<Equal<AnyOf<[0, '', false, [], { 1: 'test' }]>, true>>, Expect<Equal<AnyOf<[0, '', false, [], { name: 'test' }, { 1: 'test' }]>, true>>, Expect<Equal<AnyOf<[0, '', false, [], {}]>, false>>, Expect<Equal<AnyOf<[]>, false>>, ]