Page MenuHomePhabricator

[Flow202][native][skip-ci] [41/x] Fix type error in native/themes/colors.js
ClosedPublic

Authored by ashoat on Nov 27 2023, 1:21 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 5 2024, 7:44 AM
Unknown Object (File)
Mar 5 2024, 7:44 AM
Unknown Object (File)
Mar 5 2024, 7:43 AM
Unknown Object (File)
Mar 5 2024, 7:42 AM
Unknown Object (File)
Feb 3 2024, 5:24 AM
Unknown Object (File)
Dec 18 2023, 3:50 AM
Unknown Object (File)
Dec 17 2023, 3:07 AM
Unknown Object (File)
Dec 17 2023, 12:16 AM
Subscribers

Details

Summary

The new Flow was printing this error:

Error ------------------------------------------------------------------------------------------ themes/colors.js:304:10

Cannot return StyleSheet.create(...) because an index signature declaring the expected key / value type is read-only in
Styles [1] but writable in object type [2]. [incompatible-variance]

 [2] 285| ): StyleSheetOf<IS> {
 [1] 286|   const result: Styles = {};
        :
     301|     }
     302|     result[key] = filledInStyle;
     303|   }
     304|   return StyleSheet.create(result);
     305| }
     306|
     307| function styleSelector<IS: Styles>(

Styles actually isn't read-only, but React Native's type for StyleSheet.create limits its type param to be read-only.

I fixed it by making our StyleSheetOf type read-only. However, that exposed more errors where we use typeof unboundStyles, so I had to add $ReadOnlys to all of those.

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 D10024

Test Plan

Confirm the Flow errors go away

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable