-
Notifications
You must be signed in to change notification settings - Fork 0
/
00949-medium-anyof.ts
34 lines (31 loc) · 1.02 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
25
26
27
28
29
30
31
32
33
34
// ============= 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 AnyOf<T extends readonly any[]> = T[number] extends
| false
| 0
| ""
| []
| Record<string, never>
| undefined
| null
? false
: true;
type test1 = AnyOf<[0, "", false, [], {}, undefined, null]>;
type test2 = AnyOf<[{}]>;