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)
Fri, Nov 8, 2:30 AM
Unknown Object (File)
Fri, Nov 8, 12:50 AM
Unknown Object (File)
Sun, Oct 27, 10:49 PM
Unknown Object (File)
Sun, Oct 27, 10:33 PM
Unknown Object (File)
Sep 29 2024, 2:44 AM
Unknown Object (File)
Sep 29 2024, 2:12 AM
Unknown Object (File)
Sep 29 2024, 2:11 AM
Unknown Object (File)
Sep 6 2024, 6: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.