api types: Mark most remaining types read-only#4957
Merged
chrisbobbe merged 4 commits intozulip:masterfrom Aug 13, 2021
Merged
Conversation
Done with the following command:
$ perl -i -0pe '
s<type\ \w+\ =\ \K( \{\| $ .*? ^ \|\} );> (\$ReadOnly<$1>;)gsmx;
s<type\ \w+\ =\ \K( \{ $ .*? ^ \} );> (\$ReadOnly<$1>;)gsmx
' src/api/*Types.js
Done with this command:
$ perl -i -0pe '
s<( \w+ ) \[\]> (\$ReadOnlyArray<$1>)gsmx
' src/api/*Types.js
followed by dropping one irrelevant match inside a comment,
and propagating the read-only-ness to one spot to fix type errors.
Found by grepping (imprecisely) for object types that might not
be read-only:
$ rg -A1 '[^<]\{' src/api/*Types.js
and inspecting the results.
We switched this bit of state a while ago from object-as-map to Immutable.Map. Happened across this when grepping for non-read-only object types.
Contributor
|
Thanks, LGTM! Merged. |
This file contains hidden or 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
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.
This largely covers the remaining types here, inspired by #4948, with the help of some Perl find-and-replace.
There isn't anything special about the API that means its objects and arrays should be read-only -- after all, the actual server itself can't possibly care. But we reuse a lot of these for Redux actions and for pieces of our Redux store, where we do want things to be read-only, so it's helpful to just consistently mark here too.