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.
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: