Skip to content

Update Flow to 0.274.2 and migrate to match structures #3586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

reosarevok
Copy link
Member

@reosarevok reosarevok commented Jun 30, 2025

No new errors.

0.274.1 introduces the new match feature (0.274.2 fixes some bugs in said feature).

This is a super neat option that allows to replace switch structures with something that Flow understands a lot better (and that checks for exhaustiveness by default, meaning no need to call exhaustive explicitly anymore. I converted most of our switch to use match now. Some are better to leave as-is for now, either because we very much don't want exhaustiveness and it would not help with clarity, or because they use redux and new mock actions are introduced on runtime that we don't want to bother with just yet (since we'll migrate them eventually).

Additionally, this gets rid of the hacky chooseLayoutComponent picker and replaces it with a much more sensible and type-safe LayoutComponent using match. In order to make Flow entirely happy with it I got rid of the RecordingWithArtistCreditT distinction (now all entities with artist credits always are sent as JSON with an artist credit, an empty one is added if they lacked one). I changed a bunch of places to check whether the AC is empty rather than whether it exists to go along with this change. I also fixed the types for Subscribers (which claimed to be getting an EditorT but was actually getting an AccountLayoutUserT).

Finally, I removed a bunch of Flow ignores that no longer trigger Flow issues after some bug fix or another in the previous updates.

@reosarevok reosarevok added the Refactoring Refactoring-only PRs (eslint fixes etc) label Jun 30, 2025
@reosarevok reosarevok force-pushed the flow-274 branch 4 times, most recently from bb0a88b to 5aaed18 Compare July 3, 2025 09:49
No errors

https://github.com/facebook/flow/releases/tag/v0.274.1

Allows for the new  match pattern: https://flow.org/en/docs/match/

AFAICT this can replace our exhaustive(action); switches,
might look into it in a subsequent commit.
Just fixes some bugs in the match implementation

https://github.com/facebook/flow/releases/tag/v0.274.2
This uses the new match structure to replace all the exhaustive
switches. This allows us to drop the use of exhaustive() itself.
This also drops all the error throwing in default cases which
should never be reached if our typing is correct anyway.

See:
https://flow.org/en/docs/match/
https://flow.org/en/docs/match/migration/
This migrates most Flow-covered switch structures,
since match is nicer for exhaustiveness (I fixed a couple
of issues with unused actions
and missing strings here
thanks to that).
One match seems a lot clearer than the previous system.
This drops the always hacky (and defined as "a Flow landmine")
chooseLayoutComponent picker and uses Flow's match feature
to pick a layout based on the actual entity being displayed.
We had a separate type RecordingWithArtistCreditT because
TO_JSON didn't always come with an artist credit.
AFAICT, the same applied to RGs and releases, so in theory
we should probably also have had ReleaseWithAC and RGWithAC .
This leads to a huge pain maintaining Flow types.

AFAICT, there is no reason why we shouldn't just always return
an AC for entities that can have it - just an empty one, which is
valid in Flow.
This adds a new function nonEmptyArtistCredit()
to use in places where we care about the AC being empty
(in order to fall back to another one for example).
This is used in a ton of places, and it's mirroring a specific kind
of response from the Perl side. It seems sensible to have it
as a default type like the TO_JSON ones.
This was using EditorT, but what it actually gets is
AccountLayoutUserT (editors explicitly go through serialize_user).
@reosarevok reosarevok changed the title [WIP] Update Flow to 0.274.1 Update Flow to 0.274.2 Jul 4, 2025
@reosarevok reosarevok marked this pull request as ready for review July 4, 2025 09:54
@reosarevok reosarevok changed the title Update Flow to 0.274.2 Update Flow to 0.274.2 and migrate to match structures Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring Refactoring-only PRs (eslint fixes etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant