Make previously defined styles (typed as ViewStyle, TextStyle, etc...) retro-compatible with UnistylesValues types. #685
rrooddooxx
started this conversation in
Feature Requests
Replies: 1 comment
-
Thank you for the kind words and I'm happy that another big project will use Unistyles 🦄 After investigation I can say that the issue lies here: export type TypographyThemeTokens = {
[key in TypographyNamesThemeTokens]?: TextStyle;
}; You are limiting the type to a generic What you need to do is:
-const typographyTokens: TypographyThemeTokens = {
const typographyTokens = {
[TypographyNamesThemeTokens.BODY_3]: {
fontFamily: globalTokens.typography.fontFace.openSans.regular,
fontSize: globalTokens.typography.fontSize.xs,
}
-}
+} satisfies TypographyThemeTokens Now, if you check the type of such a construct, it's: Now you can safely spread it: const styles = StyleSheet.create(theme => ({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: theme.colors.backgroundColor
},
typography: {
...typographyTokens[TypographyNamesThemeTokens.BODY_3]
},
}) and check the type: type Z = typeof styles['typography'] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi! Thanks for your amazing work with this library. I'm pushing the usage of unistyles in a big monorepo at my current company, but I've comed across this problem while doing so, specially when trying to "inherit" previously defined styles (typed with the StyleSheet react-native typings, like ViewStyle, TextStyle, etc..), they cannot be spreaded into a StyleSheet.create({}) declaration because the
UnistylesValues
doesn't seem to overlap withViewStyle, TextStyle
etc to the TS compiler.Here's an example:
We have a lot of "design semantic tokens" implemented in code, let's say a typography body config:
This object is of type
So when I want to spread this style, like this:
I'm getting this TS error:
Is there a way we can make our previously defined (and ts typed) styles compatible with Unistyles?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions