Wrong styles type provided by useStyles which has stylesheet with Platfrom.select(...)
sapkotamadhusudan opened this issue · comments
Description
The platform-specific style property gets defaulted to ColorValue
when we use Platform.select({ android: {...}, ios: {...}, ... })
inside stylesheet.
Steps to reproduce
- Create stylesheet using Platform API
const stylesheet = createStyleSheet({
toastContainer: {
opacity: 1,
minHeight: 60,
...Platform.select({
ios: {
shadowRadius: 12,
shadowOpacity: 0.1,
shadowOffset: { width: 0, height: 1 },
shadowColor: "black",
},
android: {
elevation: 1,
},
default: {},
}),
},
});
- Use the styles in any
View
component
const { styles, theme } = useStyles(stylesheet);
<View style={styles.toastContainer} />
- All the later platform styles type will be defaulted to
ColorValue
, hereelevation
type is defaulted toColorValue
.
Snack or a link to a repository (optional)
No response
Unistyles version
2.0.0
React Native version
0.73.2
Platforms
Android, iOS, React Native Web
Engine
Hermes
Architecture
Paper (old)
Thank you for the report. I know where the issue is, it's about Unistyles TypeScript types.
I will patch it as soon as possible, but it will most likely be next week due to my vacation.
What's your TypeScript version? I'm getting different results running your example:
![Screenshot 2024-01-23 at 05 05 48](https://private-user-images.githubusercontent.com/9088288/298802061-add4da44-9a18-453b-8cd3-ac414ae9533b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0NTg5MDIsIm5iZiI6MTcyMTQ1ODYwMiwicGF0aCI6Ii85MDg4Mjg4LzI5ODgwMjA2MS1hZGQ0ZGE0NC05YTE4LTQ1M2ItOGNkMy1hYzQxNGFlOTUzM2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjBUMDY1NjQyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MGUzMzAzODQ4OGFiNjIzYWQ1NjJiMzVmNjUwMDUzNmZkMDBmNzllYzE5NTAyMGQzZDQ0MjAyMGYwOThjY2JjNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.BvMMKTf9Qhg-z7vS5FjhKRJHBwAx3HEknzsSB_XY0ag)
Type:
(property) toastContainer: {
shadowRadius: number;
shadowOpacity: number;
shadowOffset: {
width: number;
height: number;
};
shadowColor: string;
elevation?: undefined;
opacity: number;
minHeight: number;
} | {
elevation: number;
... 5 more ...;
minHeight: number;
} | {
...;
}
I'm running your example in Unistyles example
folder with Unistyles 2.0.2 and TS version set to 5.3.3
@jpudysz I'm not sure if it's my project specific, currently, I'm also using the h Unistyles 2.0.2 and TS version set to 5.3.3.
Here are the dependencies that I'm currently using.
Edit: I also tested the same code in a new project, and the issue does not exist. Maybe it's due to the project configurations, will investigate further and let you know.
Oh, thanks for the edit!
To be honest, I don't know why you have a different output. It should be exactly the same for everyone.
I will be waiting for your reply about this issue as I'm intrigued 🤔
@jpudysz Finally! After comparing every part with the new project, able to solve the issue. Not sure why it was caused.
I did added the compilerOptions i.e "strict": true,
in tsconfig.json
✨ its working.
Thanks for the hint!
If someone will encounter it again I will mention it in the docs 💪