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
F3349351: D10025.diff
Fri, Nov 22, 5:46 PM
Unknown Object (File)
Wed, Nov 6, 7:17 AM
Unknown Object (File)
Fri, Nov 1, 10:23 PM
Unknown Object (File)
Oct 17 2024, 11:50 AM
Unknown Object (File)
Oct 17 2024, 11:50 AM
Unknown Object (File)
Oct 17 2024, 11:49 AM
Unknown Object (File)
Oct 17 2024, 11:49 AM
Unknown Object (File)
Oct 16 2024, 7:00 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
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 24467
Build 210198: arc lint + arc unit