Skip to content

Commit

Permalink
lint: make Props types readonly (step 3 of 3)
Browse files Browse the repository at this point in the history
Make the last few Props types [1] readonly.

This is done manually. The few remaining Props types fall largely into
two categories:

- types defined using `$Diff`; and
- nonempty exact types defined inline.

The former have been manually wrapped with $ReadOnly<>. The latter
have had their entries prefixed with `+`, which for exact types has
essentially the same effect. (See [the flow documentation] and [the original
PR].)

[1] Or at least, the last few Props types detected by `eslint-plugin-flowtype`.

[the flow documentation]: https://flow.org/en/docs/types/interfaces/#toc-covariant-read-only-properties-on-interfaces
[the original PR]: gajus/eslint-plugin-flowtype#400
  • Loading branch information
rk-for-zulip committed Nov 7, 2019
1 parent cb2e211 commit 2e8f2a4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/account-info/ProfileCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const styles = StyleSheet.create({
},
});

class SetStatusButton extends PureComponent<{| dispatch: Dispatch |}> {
class SetStatusButton extends PureComponent<{| +dispatch: Dispatch |}> {
onPress = () => {
const { dispatch } = this.props;
dispatch(navigateToUserStatus());
Expand All @@ -39,7 +39,7 @@ class SetStatusButton extends PureComponent<{| dispatch: Dispatch |}> {
}
}

class SwitchAccountButton extends PureComponent<{| dispatch: Dispatch |}> {
class SwitchAccountButton extends PureComponent<{| +dispatch: Dispatch |}> {
onPress = () => {
this.props.dispatch(navigateToAccountPicker());
};
Expand All @@ -51,7 +51,7 @@ class SwitchAccountButton extends PureComponent<{| dispatch: Dispatch |}> {
}
}

class LogoutButton extends PureComponent<{| dispatch: Dispatch |}> {
class LogoutButton extends PureComponent<{| +dispatch: Dispatch |}> {
onPress = () => {
const { dispatch } = this.props;
dispatch(tryStopNotifications());
Expand Down
2 changes: 1 addition & 1 deletion src/boot/TranslationProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const makeGetText = (intl: IntlShape): GetText => {
* vs. https://reactjs.org/docs/legacy-context.html .
*/
class TranslationContextTranslator extends PureComponent<{
children: React$Node,
+children: React$Node,
}> {
context: { intl: IntlShape };

Expand Down
2 changes: 1 addition & 1 deletion src/common/InputWithClearButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const componentStyles = StyleSheet.create({
},
});

type Props = $Diff<InputProps, { textInputRef: mixed, value: mixed }>;
type Props = $ReadOnly<$Diff<InputProps, { textInputRef: mixed, value: mixed }>>;

type State = {|
canBeCleared: boolean,
Expand Down
4 changes: 2 additions & 2 deletions src/common/PasswordInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const styles = StyleSheet.create({

// Prettier wants a ", >" here, which is silly.
// prettier-ignore
type Props = $Diff<InputProps,
type Props = $ReadOnly<$Diff<InputProps,
// "mixed" here is a way of spelling "no matter *what* type
// `InputProps` allows for these, don't allow them here."
{ secureTextEntry: mixed, autoCorrect: mixed, autoCapitalize: mixed }>;
{ secureTextEntry: mixed, autoCorrect: mixed, autoCapitalize: mixed }>>;

type State = {|
isHidden: boolean,
Expand Down

0 comments on commit 2e8f2a4

Please sign in to comment.