Skip to content

Commit

Permalink
Fix return type of StyleSheet.create to be the identity function
Browse files Browse the repository at this point in the history
Summary:
Changes the return type of StyleSheet.create to `$ReadOnly<S>`. 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
  • Loading branch information
jbrown215 authored and facebook-github-bot committed Jan 2, 2020
1 parent 26650c7 commit 4e71a30
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Libraries/LogBox/UI/LogBoxNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function LogBoxLogNotification(props: Props): React.Node {
function CountBadge(props) {
return (
<View style={countStyles.outside}>
{/* $FlowFixMe(>=0.114.0) This suppression was added when fixing the type
* of `StyleSheet.create`. Remove this comment to see the error. */}
<View style={[countStyles.inside, countStyles[props.level]]}>
<Text style={countStyles.text}>
{props.count <= 1 ? '!' : props.count}
Expand Down
2 changes: 1 addition & 1 deletion Libraries/StyleSheet/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ module.exports = {
/**
* Creates a StyleSheet style reference from the given object.
*/
create<+S: ____Styles_Internal>(obj: S): $ObjMap<S, (Object) => any> {
create<+S: ____Styles_Internal>(obj: S): $ReadOnly<S> {
// 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).
Expand Down

0 comments on commit 4e71a30

Please sign in to comment.