Skip to content

[react-native] Specify more detailed type of hardwareBackPress handler#42618

Closed
ghost wants to merge 1 commit into
masterfrom
unknown repository
Closed

[react-native] Specify more detailed type of hardwareBackPress handler#42618
ghost wants to merge 1 commit into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Feb 25, 2020

Copy link
Copy Markdown

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

Select one of these and delete the others:

If changing an existing definition:


While the docs say that the handler should return true when the handling should stop, in the implementation, any truthy value does that.

@ghost
ghost requested a review from alloy as a code owner February 25, 2020 16:58
@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Awaiting reviewer feedback labels Feb 25, 2020
@typescript-bot

typescript-bot commented Feb 25, 2020

Copy link
Copy Markdown
Contributor

@st-sloth Thank you for submitting this PR!

🔔 @alloy @huhuanming @iRoachie @Skn0tt @timwangdev @kamal @alexdunne @swissmanu @bm-software @a-tarasyuk @mvdam @Esemesek @mrnickel @souvik-ghosh @nossbigg @saranshkataria @franzmoro @tykus160 @jakebloom @ceyhun @mcmar @theohdv @TheSavior @romain-faust @bebebebebe @Naturalclar @chinesedfan @vtolochk @SychevSP @RageBill @sasurau4 @256hz @doumart @drmas - please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Merge:Express and removed Awaiting reviewer feedback labels Feb 25, 2020
@typescript-bot

Copy link
Copy Markdown
Contributor

A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped!

addEventListener(eventName: BackPressEventName, handler: () => void): NativeEventSubscription;
removeEventListener(eventName: BackPressEventName, handler: () => void): void;
addEventListener(eventName: BackPressEventName, handler: () => true | void): NativeEventSubscription;
removeEventListener(eventName: BackPressEventName, handler: () => true | void): void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems incorrect.. Even without this change, you should be able to pass handle that returns true

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, one is already able to pass a handler that returns anything at all, as no return value is strictly needed. However the handler must return true, as per documentation (or actually any truthy value, as per implementation), to cause specific behaviour - stopping all the subsequent listeners, including the default one, from executing. And it seems appropriate to document that the handler "should" return true or nothing (even though, in the implementation, the return value is typecasted to boolean, and any value is possible).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Flow version doesn’t really say anything about return type. Looking at the docs and the implementation, it seems to me like this should just be () => boolean, but perhaps () => boolean | null | undefined is acceptable too.

In any case, it would be good to send a similar change upstream, unless I’m overlooking a reason for this to not be typed as such already. /cc @TheSavior

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not familiar with this. If the flow code doesn’t include boolean then it is likely that we don’t have any callsites doing that, which makes me not trust the documentation. Can you verify the runtime behavior of the listeners and behavior of returning true?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elicwhite elicwhite Feb 26, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay, I understand better now. The flow code for those functions is untyped. Function is the same as any. I think having the type be boolean | void is reasonable. Please upstream a PR making it typed as returning ?boolean.

@alloy alloy Feb 27, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having the type be boolean | void is reasonable. Please upstream a PR making it typed as returning ?boolean.

Just to be sure we’re all on the same page; I assume you meant the Flow equivalent that I posted: () => boolean | null | undefined. Using void would I think send the wrong message, i.e. that the return value would not lead to effects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I was agreeing with what you posted :-) Thanks for checking

@typescript-bot typescript-bot added Revision needed This PR needs code changes before it can be merged. and removed Merge:Express labels Feb 26, 2020
@typescript-bot

Copy link
Copy Markdown
Contributor

@st-sloth One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. Thank you!

@typescript-bot

Copy link
Copy Markdown
Contributor

@st-sloth I haven't seen anything from you in a while and this PR currently has problems that prevent it from being merged. The PR will be closed tomorrow if there aren't new commits to fix the issues.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Mar 4, 2020
@typescript-bot

Copy link
Copy Markdown
Contributor

@st-sloth To keep things tidy, we have to close PRs that aren't mergeable but don't have activity from their author. No worries, though - please open a new PR if you'd like to continue with this change. Thank you!

facebook-github-bot pushed a commit to react/react-native that referenced this pull request Apr 23, 2020
Summary:
Following the comment DefinitelyTyped/DefinitelyTyped#42618 (comment)

Modify the flowtype of BackHandler function to have more specific return type.

## Changelog

[General] [Changed] - Changed type of BackHandler to be more specific.
Pull Request resolved: #28192

Test Plan: No flow error in RNTester

Reviewed By: TheSavior

Differential Revision: D20771113

Pulled By: hramos

fbshipit-source-id: 5ca65e2a2b3f8726b8fb4606473d8fad5b0ce730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Abandoned This PR had no activity for a long time, and is considered abandoned Owner Approved A listed owner of this package signed off on the pull request. Popular package This PR affects a popular package (as counted by NPM download counts). Revision needed This PR needs code changes before it can be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants