Page MenuHomePhabricator

[Flow202][lib][skip-ci] [7/23] Fix Flow issues in useUpdateThemePreference by replacing let expression with ternary
ClosedPublic

Authored by ashoat on Nov 4 2023, 11:59 AM.
Tags
None
Referenced Files
F3539679: D9699.id33796.diff
Thu, Dec 26, 3:10 AM
F3539677: D9699.id32703.diff
Thu, Dec 26, 3:10 AM
F3539566: D9699.diff
Thu, Dec 26, 2:52 AM
Unknown Object (File)
Mon, Dec 23, 6:59 AM
Unknown Object (File)
Fri, Dec 20, 9:55 PM
Unknown Object (File)
Mon, Dec 16, 12:50 AM
Unknown Object (File)
Mon, Dec 2, 10:51 AM
Unknown Object (File)
Mon, Dec 2, 9:09 AM
Subscribers

Details

Summary

The new version of Flow wants an annotation on the let expression that covers the later assignment:

Error --------------------------------------------------------------------------------------------- hooks/theme.js:54:17

Cannot assign globalThemeInfo.systemTheme to theme because null or undefined [1] is incompatible with literal union [2].
All writes to theme must be compatible with the type of its initializer [3]. Add an annotation to theme [3] if a
different type is desired. [incompatible-type]

     hooks/theme.js
 [2] 47|     (themePreference: GlobalThemePreference) => {
     48|       if (themePreference === globalThemeInfo.preference) {
     49|         return;
     50|       }
     51|
 [3] 52|       let theme = themePreference;
     53|       if (themePreference === 'system') {
     54|         theme = globalThemeInfo.systemTheme;
     55|       }
     56|
     57|       dispatch({

     types/theme-types.js
 [1]  8|   +systemTheme: ?GlobalTheme,

Instead of doing that, I figured this was more readable as a const ternary expression anyways, which also conveniently lets us skip the typehint.

NOTE: CI will fail on this diff. I considered the possibility of fixing Flow errors BEFORE upgrading Flow, but it wasn't possible... in some cases, the fixes to support the new version of Flow caused errors in the old version. I could have hidden these type errors with $FlowFixMe lines and then later revert those, but that seemed like too much busy work.

Depends on D9698

Test Plan

Confirm the Flow errors go away

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Harbormaster returned this revision to the author for changes because remote builds failed.Nov 4 2023, 12:15 PM
Harbormaster failed remote builds in B23741: Diff 32703!
This revision is now accepted and ready to land.Nov 6 2023, 7:44 PM
ashoat retitled this revision from [Flow202][lib] [7/23] Fix Flow issues in useUpdateThemePreference by replacing let expression with ternary to [Flow202][lib][skip-ci] [7/23] Fix Flow issues in useUpdateThemePreference by replacing let expression with ternary.Nov 19 2023, 11:46 AM
This revision was landed with ongoing or failed builds.Nov 27 2023, 3:25 PM
This revision was automatically updated to reflect the committed changes.