Total Complexity | 3 |
Complexity/F | 1 |
Lines of Code | 36 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | export {} |
||
2 | type ClassHash = string | undefined |
||
3 | |||
4 | type Props = { |
||
5 | Btn: ClassHash |
||
6 | isValid: boolean |
||
7 | isOpen?: boolean |
||
8 | } |
||
9 | |||
10 | const { |
||
11 | Btn, |
||
12 | isOpen, |
||
13 | isValid |
||
14 | } = {} as Props |
||
15 | |||
16 | classNaming( |
||
17 | guard1({Btn, Btn__Open: isOpen, Btn__Valid: isValid}) |
||
18 | ) |
||
19 | //@ts-expect-error |
||
20 | guard2({Btn, Btn__Open: isOpen, Btn__Valid: isValid}) |
||
21 | |||
22 | function guard1< |
||
23 | E extends Record<string, ClassHash|boolean> |
||
24 | >(source: E) { |
||
25 | return source as unknown as {[K in keyof E]: E[K] extends boolean ? boolean : E[K] extends ClassHash ? ClassHash : never} |
||
26 | } |
||
27 | |||
28 | function guard2<T>(source: T extends Record<infer K, ClassHash|boolean> ? { |
||
29 | [k in K]: T[k] extends boolean ? T[k] : T[k] extends ClassHash ? T[k] : never |
||
30 | } : never) { |
||
31 | return source |
||
32 | } |
||
33 | |||
34 | function classNaming<T>(source: T) { |
||
35 | return source |
||
36 | } |