Skip to content

Commit c4ae130

Browse files
committed
fix: improved issue with typings
1 parent ef23f6b commit c4ae130

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/jacaranda/src/index.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@
4040
// }
4141
// });
4242

43-
import { ImageStyle, TextStyle, ViewStyle, DimensionValue } from 'react-native';
43+
import { ImageStyle, TextStyle, ViewStyle, StyleProp } from 'react-native';
4444

45-
type TokenString = `$${string}`;
45+
// Define a type that removes token strings from style properties
46+
type ResolvedStyle = ViewStyle & TextStyle & ImageStyle;
4647

47-
export type StyleObject = Partial<{
48-
[K in keyof (ViewStyle & TextStyle & ImageStyle)]:
49-
| (ViewStyle & TextStyle & ImageStyle)[K]
50-
| (K extends keyof ViewStyle ? TokenString | DimensionValue : TokenString);
51-
}>;
48+
// StyleObject now extends ResolvedStyle
49+
type StyleObject = {
50+
[K in keyof ResolvedStyle]?:
51+
| ResolvedStyle[K]
52+
| (string extends ResolvedStyle[K] ? `$${string}` : never)
53+
| (number extends ResolvedStyle[K] ? `$${string}` : never);
54+
};
5255

5356
// Define the VariantOptions type to ensure type safety in variant definitions
5457
type VariantOptions<V> = {
@@ -98,7 +101,7 @@ export function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V
98101
type DefaultProps = NonNullable<typeof config.defaultVariants>;
99102
type Props = OptionalIfHasDefault<VariantProps, DefaultProps>;
100103

101-
return (props?: Props) => {
104+
return (props?: Props): StyleProp<ResolvedStyle> => {
102105
// Start with base styles
103106
let styles: StyleObject = {
104107
...(config.base || {}),
@@ -140,7 +143,7 @@ export function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V
140143
}
141144
}
142145

143-
return styles;
146+
return styles as StyleProp<ResolvedStyle>;
144147
};
145148
}
146149

@@ -154,8 +157,6 @@ interface AllowedTokenCategories {
154157
fontSizes: number;
155158
fonts: string;
156159
lineHeight: number;
157-
borderWidth: number;
158-
borderStyles: 'solid' | 'dashed' | 'dotted' | 'none';
159160
}
160161

161162
// Update TokenConfig to only allow specific categories

0 commit comments

Comments
 (0)