Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] tw.variants type is not correctly inferred #115

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/tailwindest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# tailwindest

## 2.3.4

### Patch Changes

- Fix invalid typing at createTools.variants

## 2.3.3

### Patch Changes
Expand Down
24 changes: 6 additions & 18 deletions packages/tailwindest/__tests__/get.variants.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,9 @@ describe(label.unit("GetVariants - variants: with boolean | number"), () => {
onlyTrue?: true
onlyFalse?: false
numbers?: 1 | 2
never?: "Error: typeof variants key should be <string> | <number> | <'true' | 'false'>"
withNever?:
| "withNever"
| "Error: typeof variants key should be <string> | <number> | <'true' | 'false'>"
combinations?:
| 1
| boolean
| "withNever"
| "Error: typeof variants key should be <string> | <number> | <'true' | 'false'>"
never?: never
withNever?: "withNever"
combinations?: 1 | boolean | "withNever"
}
>
>(true)
Expand All @@ -252,15 +246,9 @@ describe(label.unit("GetVariants - variants: with boolean | number"), () => {
onlyTrue?: true
onlyFalse?: false
numbers?: 1 | 2
never?: "Error: typeof variants key should be <string> | <number> | <'true' | 'false'>"
withNever?:
| "withNever"
| "Error: typeof variants key should be <string> | <number> | <'true' | 'false'>"
combinations?:
| 1
| boolean
| "withNever"
| "Error: typeof variants key should be <string> | <number> | <'true' | 'false'>"
never?: never
withNever?: "withNever"
combinations?: 1 | boolean | "withNever"
}
>
>(true)
Expand Down
2 changes: 1 addition & 1 deletion packages/tailwindest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tailwindest",
"version": "2.3.3",
"version": "2.3.4",
"description": "typesafe, reusable tailwind",
"homepage": "https://tailwindest.vercel.app",
"author": "danpacho",
Expand Down
6 changes: 1 addition & 5 deletions packages/tailwindest/src/core/tools/create.rotary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import type { TailwindestStyler } from "./tool.interface"

const createRotary =
<StyleType>() =>
<
VariantsStylesType extends {
[key in keyof VariantsStylesType]: StyleType
},
>({
<VariantsStylesType>({
base,
...styles
}: { [key in keyof VariantsStylesType]: StyleType } & {
Expand Down
21 changes: 8 additions & 13 deletions packages/tailwindest/src/create.tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ const createTools = <StyleType>(): {
* )
* ```
*/
rotary: <
VariantsStylesType extends {
[key in keyof VariantsStylesType]: StyleType
},
>({
rotary: <VariantsStylesType>({
base,
...styles
}: { [key in keyof VariantsStylesType]: StyleType } & {
Expand Down Expand Up @@ -184,17 +180,16 @@ const createTools = <StyleType>(): {
* )
* ```
*/
variants: <
Variants extends {
[VariantsKey in keyof Variants]: {
[key in keyof Variants[VariantsKey]]: StyleType
}
},
>({
variants: <Variants>({
base,
variants,
}: {
variants: Variants
variants: {
[VariantsKey in keyof Variants]: Record<
keyof Variants[VariantsKey],
StyleType
>
}
} & {
base?: StyleType
}) => {
Expand Down
Loading