HomePhabricator
Diffusion Comm c23795311cef

[Flow202][lib][skip-ci] [7/23] Fix Flow issues in useUpdateThemePreference by…

Description

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

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

Reviewers: ginsu

Reviewed By: ginsu

Subscribers: tomek, wyilio

Differential Revision: https://phab.comm.dev/D9699