-
Notifications
You must be signed in to change notification settings - Fork 0
/
00949-medium-anyof.ts
28 lines (25 loc) · 1021 Bytes
/
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
25
26
27
28
// ============= 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, [], {}, undefined, null]>, false>>,
Expect<Equal<AnyOf<[]>, false>>
]
// ============= Your Code Here =============
type Falsy = { [key: string]: never } | false | 0 | '' | null | undefined | []
type AnyOf<T extends readonly any[]> = T extends [infer Head, ...infer Tail]
? Head extends Falsy
? AnyOf<Tail>
: true
: false