mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51488 The Flow team is improving the way Flow infers type for primitive literals. Announcement: https://fb.workplace.com/groups/flowlang/permalink/1725180268087629/ This diff prepares the codebase for the new behavior by codemoding `as const` annotations. ## Repro steps 1/ Used steps in D73610163 to produce the code changes. 2/ Reverted files where `flow` errored: ``` flow status --show-all-errors > errors.log node ~/fbsource/fbcode/flow/facebook/error-analyzer.js errors.log | awk -F':' '{ print $1 }' | sort -u | grep -v 'Total Error Count' | xargs hg revert --rev . ``` 3/ Reverted files that did not improve error count in new Flow mode ``` # Run Flow before change ~/fbsource/fbcode/flow/facebook/flowd status --show-all-errors > errors-0.log # Run Flow after change ~/fbsource/fbcode/flow/facebook/flowd status --show-all-errors > errors-1.log # Compute error counts before and after node ~/fbsource/fbcode/flow/facebook/error-analyzer.js errors-0.log | sort > errors-counts-0.log node ~/fbsource/fbcode/flow/facebook/error-analyzer.js errors-1.log | sort > errors-counts-1.log # Revert files with no change in error count comm -12 errors-counts-0.log errors-counts-1.log | awk -F':' '{ print $1 }' | xargs hg revert --rev .~1 ``` ## Note to code owners Due to the large number of errors involved in this rollout, adding `as const` was the most feasible large-scale automated solution. Ideally, a lot of these errors would be fixed by adding other appropriate type annotations. For example instead of annotating ``` type Shape = {type: 'circle', radius: number} | {type: 'square', side: number} | ...; type ShapeKind = 'circle' | 'square' | 'triangle'; const circle = { type: "circle" as const, // <-- annotation added here radius: 42, }; shape.type as ShapeKind; takesShape(circle); ``` a more appropriate annotation would be ``` const circle: Circle = { type: "circle"; radius: 42 }; ... ``` Changelog: [Internal] drop-conflicts Reviewed By: SamChou19815 Differential Revision: D75114154 fbshipit-source-id: 67ee5673816da9625431e2a2466a1e0038386151