From 4e71a30969d74073309d0350be55cadb84ae43ff Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 2 Jan 2020 09:57:36 -0800 Subject: [PATCH] Fix return type of StyleSheet.create to be the identity function Summary: Changes the return type of StyleSheet.create to `$ReadOnly`. At runtime, it just freezes the fields in dev mode and is the identity function otherwise. This cause 423 errors due to the wrong props being passed to different styles: P124372727 I went over errors at random with Eli to get confidence in the change. Changelog: [General][Fixed] Fix return type of StyleSheet.create Reviewed By: zackargyle, TheSavior Differential Revision: D19218817 fbshipit-source-id: b7aa10700f8333372c9f0bd61bfbef371caadf97 --- Libraries/LogBox/UI/LogBoxNotification.js | 2 ++ Libraries/StyleSheet/StyleSheet.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/LogBox/UI/LogBoxNotification.js b/Libraries/LogBox/UI/LogBoxNotification.js index eb2b52a58544c6..e2623b2694435f 100644 --- a/Libraries/LogBox/UI/LogBoxNotification.js +++ b/Libraries/LogBox/UI/LogBoxNotification.js @@ -60,6 +60,8 @@ function LogBoxLogNotification(props: Props): React.Node { function CountBadge(props) { return ( + {/* $FlowFixMe(>=0.114.0) This suppression was added when fixing the type + * of `StyleSheet.create`. Remove this comment to see the error. */} {props.count <= 1 ? '!' : props.count} diff --git a/Libraries/StyleSheet/StyleSheet.js b/Libraries/StyleSheet/StyleSheet.js index 1a1fea49e4fd3e..54094d8bd4929e 100644 --- a/Libraries/StyleSheet/StyleSheet.js +++ b/Libraries/StyleSheet/StyleSheet.js @@ -347,7 +347,7 @@ module.exports = { /** * Creates a StyleSheet style reference from the given object. */ - create<+S: ____Styles_Internal>(obj: S): $ObjMap any> { + create<+S: ____Styles_Internal>(obj: S): $ReadOnly { // TODO: This should return S as the return type. But first, // we need to codemod all the callsites that are typing this // return value as a number (even though it was opaque).