-
Notifications
You must be signed in to change notification settings - Fork 0
/
00949-medium-anyof.ts
24 lines (19 loc) · 1.12 KB
/
00949-medium-anyof.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// ============= Test Cases =============
import type { Equal, Expect } from './test-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>>,
]
// ============= Your Code Here =============
type IsTrue<T> = T extends (0 | '' | false | [] | Record<string,never>) ? false: true
// type AnyOf<T extends readonly any[]> = T extends [infer R, ...infer P] ? (IsTrue<R> extends true ? true : AnyOf<P>) : false
type AnyOf<T extends readonly any[]> = IsTrue<T[number]> extends false ? false: true
// ref: https://github.com/type-challenges/type-challenges/issues/13890