Skip to content

Commit b535771

Browse files
committed
Fix type test for spacing
1 parent cadf334 commit b535771

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/lib/spacing.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,47 @@ export function spacing<
2020
params: Params
2121
): (Params extends { topBottom: SpacingToken | number }
2222
? Record<
23-
`${"top" | "bottom"}${Capitalize<Kind>}`,
23+
`${Kind}${"Top" | "Bottom"}`,
2424
Params["topBottom"] extends SpacingToken
2525
? SpacingTokenByValue[Params["topBottom"]]
2626
: Params["topBottom"]
2727
>
2828
: {}) &
2929
(Params extends { rightLeft: SpacingToken | number }
3030
? Record<
31-
`${"right" | "left"}${Capitalize<Kind>}`,
31+
`${Kind}${"Right" | "Left"}`,
3232
Params["rightLeft"] extends SpacingToken
3333
? SpacingTokenByValue[Params["rightLeft"]]
3434
: Params["rightLeft"]
3535
>
3636
: {}) &
3737
(Params extends { top: SpacingToken | number }
3838
? Record<
39-
`top${Capitalize<Kind>}`,
39+
`${Kind}Top`,
4040
Params["top"] extends SpacingToken
4141
? SpacingTokenByValue[Params["top"]]
4242
: Params["top"]
4343
>
4444
: {}) &
4545
(Params extends { right: SpacingToken | number }
4646
? Record<
47-
`right${Capitalize<Kind>}`,
47+
`${Kind}Right`,
4848
Params["right"] extends SpacingToken
4949
? SpacingTokenByValue[Params["right"]]
5050
: Params["right"]
5151
>
5252
: {}) &
5353
(Params extends { bottom: SpacingToken | number }
5454
? Record<
55-
`bottom${Capitalize<Kind>}`,
55+
`${Kind}Bottom`,
5656
Params["bottom"] extends SpacingToken
5757
? SpacingTokenByValue[Params["bottom"]]
5858
: Params["bottom"]
5959
>
6060
: {}) &
6161
(Params extends { left: SpacingToken | number }
6262
? Record<
63-
`left${Capitalize<Kind>}`,
63+
`${Kind}Left`,
6464
Params["left"] extends SpacingToken
6565
? SpacingTokenByValue[Params["left"]]
6666
: Params["left"]

test/types/spacint.ts renamed to test/types/spacing.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,71 @@ import { assert } from "tsafe/assert";
33
import { Equals } from "tsafe";
44

55
{
6-
const got = spacing("margin", { "topBottom": "1v" });
6+
const got = spacing("margin", { "topBottom": 4 });
77

8-
type Expected = Record<"topMargin" | "bottomMargin", "0.25rem">;
8+
type Expected = {
9+
marginTop: number;
10+
marginBottom: number;
11+
};
912

1013
assert<Equals<typeof got, Expected>>();
1114
}
1215

1316
{
1417
const got = spacing("margin", { "topBottom": "1v" });
1518

16-
type Expected = Record<"topMargin" | "bottomMargin", "0.25rem">;
19+
type Expected = {
20+
marginTop: "0.25rem";
21+
marginBottom: "0.25rem";
22+
};
1723

1824
assert<Equals<typeof got, Expected>>();
1925
}
2026

2127
{
2228
const got = spacing("margin", { "topBottom": "1v", "rightLeft": 33 });
2329

24-
type Expected = Record<"topMargin" | "bottomMargin", "0.25rem"> &
25-
Record<"leftMargin" | "rightMargin", number>;
30+
type Expected = {
31+
marginTop: "0.25rem";
32+
marginBottom: "0.25rem";
33+
marginLeft: number;
34+
marginRight: number;
35+
};
2636

2737
assert<Equals<typeof got, Expected>>();
2838
}
2939

3040
{
3141
const got = spacing("margin", { "topBottom": "1v", "rightLeft": 33 });
3242

33-
type Expected = Record<"topMargin" | "bottomMargin", "0.25rem"> &
34-
Record<"leftMargin" | "rightMargin", number>;
43+
type Expected = {
44+
marginTop: "0.25rem";
45+
marginBottom: "0.25rem";
46+
marginLeft: number;
47+
marginRight: number;
48+
};
3549

3650
assert<Equals<typeof got, Expected>>();
3751
}
3852

3953
{
4054
const got = spacing("margin", { "bottom": "1v" });
4155

42-
type Expected = Record<"bottomMargin", "0.25rem">;
56+
type Expected = {
57+
marginBottom: "0.25rem";
58+
};
4359

4460
assert<Equals<typeof got, Expected>>();
4561
}
4662

4763
{
4864
const got = spacing("padding", { "bottom": "1v", "rightLeft": 42 });
4965

50-
type Expected = Record<"rightPadding" | "leftPadding", number> &
51-
Record<"bottomPadding", "0.25rem">;
66+
type Expected = {
67+
paddingRight: number;
68+
paddingLeft: number;
69+
paddingBottom: "0.25rem";
70+
};
5271

5372
assert<Equals<typeof got, Expected>>();
5473
}

0 commit comments

Comments
 (0)