-
Notifications
You must be signed in to change notification settings - Fork 24.2k
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
StyleSheet.flatten with a falsy value returns undefined #46293
Labels
API: StyleSheet
Issue: Author Provided Repro
This issue can be reproduced in Snack or an attached project.
Comments
Hi @hazelmeow, thanks for the report. Out of curiosity, have you tried this in 0.74 also? |
@cipolleschi Just tested on RN 0.74.5, same behavior on iOS at least (and I would assume Android is the same). The snack is Expo 51 so I think that should also be 0.74 but I'm not 100% sure. |
cortinico
added
Issue: Author Provided Repro
This issue can be reproduced in Snack or an attached project.
and removed
Needs: Triage 🔍
labels
Sep 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
API: StyleSheet
Issue: Author Provided Repro
This issue can be reproduced in Snack or an attached project.
Description
On iOS and Android (not web), calling
StyleSheet.flatten
with null/undefined/false returnsundefined
.The TypeScript signature of
flatten
isflatten<T>(style?: StyleProp<T>): T
. null/undefined/false are validStyleProp
s, so passing them to flatten should be valid, but flatten is supposed to returnT
(some style object), and undefined is usually not a validT
.Widening the return type of
flatten
toT | undefined
is an option, but would be a public API change. I think changing the function to return{}
for falsy values is more correct, since you probably want to get a final computed, flattened style object, and don't care what the input was or if it was falsy.Steps to reproduce
On iOS or Android:
React Native Version
0.75.2
Affected Platforms
Runtime - Android, Runtime - iOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://snack.expo.dev/@catboyfan/stylesheet-flatten-undefined
Screenshots and Videos
No response
The text was updated successfully, but these errors were encountered: