Skip to content

Commit 394b21c

Browse files
author
Andrii Kirmas
committed
#38 Sandbox bootstrap's "visible-print"
1 parent b751375 commit 394b21c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

__sandbox__/atom.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Cut, Strip, UnionToIntersection } from "src/ts-swiss.types"
2+
3+
it("stripper", () => {
4+
type C1 = `${"visible-print"}-${"inline"|"block"|"inline-block"}`|`col${""|"-y"|"-x"}`|"display"
5+
type Pairs<classes extends string> = {
6+
[root in Strip<classes, "-">]: {
7+
[m1 in Merge<root, `${root}-${Strip<Cut<classes, `${root}-`, true>, "-">}`>]: true
8+
}
9+
}
10+
11+
type Merge<Base extends string, Result extends string> = [Result] extends [never] ? Base : [UnionToIntersection<Result>] extends [never] ? Base : Result
12+
13+
const checks: Record<string, Pairs<C1>> = {
14+
"x": {
15+
visible: {"visible-print": true},
16+
col: {col: true},
17+
display: {display: true}
18+
}
19+
}
20+
21+
expect(checks).toBeInstanceOf(Object)
22+
})

src/ts-swiss.types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ export type PartDeep<T> = Exclude<T, AnyObject>
5151
)
5252

5353
export type KeyOf<T> = [T] extends [never] ? never : T extends AnyObject ? Extract<keyof T, string> : never
54+
55+
/** @see https://stackoverflow.com/a/50375286/10325032 */
56+
export type UnionToIntersection<Union> = (
57+
Union extends any ? (argument: Union) => void : never
58+
) extends (argument: infer Intersection) => void
59+
? Intersection
60+
: never;

0 commit comments

Comments
 (0)