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
Unknown Object (File)
Tue, May 7, 10:20 AM
Unknown Object (File)
Wed, May 1, 3:42 PM
Unknown Object (File)
Tue, Apr 30, 6:28 PM
Unknown Object (File)
Mon, Apr 15, 8:44 PM
Unknown Object (File)
Sun, Apr 14, 9:52 PM
Unknown Object (File)
Sun, Apr 14, 9:52 PM
Unknown Object (File)
Sun, Apr 14, 7:56 AM
Unknown Object (File)
Apr 12 2024, 7:48 PM
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.