-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
Mark a bunch more object and array types read-only #5186
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This will make it possible to still instantiate `Dispatch` with our `Action` type while marking its `type` property as read-only.
Noticed one of these while writing the previous commit. Went and fixed them all, because `any` delenda est. The `*` syntax is deprecated entirely, and mostly just means `any`: https://flow.org/en/docs/types/utilities/#toc-existential-type https://flow.org/en/docs/linting/rule-reference/#toc-deprecated-type All of these `any` uses (including the `*`) look like they were driven by the lack of appropriate variance annotations `+` and `-`: https://flow.org/en/docs/types/generics/#toc-variance-sigils https://flow.org/en/docs/types/interfaces/#toc-interface-property-variance-read-only-and-write-only In each case, the appropriate real (non-`any`) type becomes available only when the appropriate variance annotations are added elsewhere (including the one added to `Dispatch`'s type parameter in the previous commit.) So add the needed variance annotations, and then give these the appropriate not-`any` types.
This will let us mark all the array types in our various Redux actions read-only, too.
This was capable of getting Flow confused, unsure of which of these two branches to try. (In particular that would happen after making all these action types read-only.)
In particular this covers all the numerous branches of our `Action` union. It doesn't cover the various object types embedded inside these; we'll get to those separately. Done with: $ perl -i -0pe ' s<type\ \w+\ =\ \K( \{\| $ .*? ^ \|\} );> (\$ReadOnly<$1>;)gsmx; s<type\ \w+\ =\ \K( \{ $ .*? ^ \} );> (\$ReadOnly<$1>;)gsmx ' src/{action,api/event}Types.js
Done with: $ perl -i -0pe ' s<( \w+ ) \[\]> (\$ReadOnlyArray<$1>)gsmx; s/\bArray\b</\$ReadOnlyArray</g ' src/{action,api/event}Types.js
Previously we covered all the object types that are given names, with `type Foo = …` declarations. This covers the remainder, found more deeply nested inside such types. Found relevant types with: $ git grep -C2 '^ .*\{' src/{action,api/event}Types.js and then just edited by hand. We also take the opportunity to tighten the formatting slightly in a couple of places.
Much like the preceding three commits, but on reduxTypes.js .
This became unnecessary when this line's fixme was lifted in d96c6ca.
Done with: $ perl -i -0pe ' s<( \w+ ) \[\]> (\$ReadOnlyArray<$1>)gsmx; s/\bArray\b</\$ReadOnlyArray</g ' src/**/*.js $ tools/fmt followed by reviewing the changes, and reverting those that weren't appropriate (which were perhaps 1/3 of the total) with commands like `git restore -p src/foo/bar.js`.
Great, thanks a lot! LGTM, merged. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Including all the object and array types in our actions and other Redux-related types, and a bunch of miscellaneous others.
The lack of read-only markings on the type for (Redux actions for)
update_message
events,EventUpdateMessageAction
, produced some very confusing Flow errors in tests when I started changing those (for #5187), sending me down a path of at least a half-hour of debugging. (It was a real type error, it turned out -- a missingsubject
property, which for now our types believe is required there.)And it turns out I had a draft branch from last summer with that and the other action types, and a few more changes. So, here's that branch finished up, along with some further changes in the same direction.