Skip to content
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

Fix add listener types #246

Merged
merged 2 commits into from
May 5, 2021
Merged

Conversation

Mookiies
Copy link
Contributor

@Mookiies Mookiies commented Apr 23, 2021

Summary

Fix TypeScript types for the addListener method for two scenarios:

1: addListener supports a null uploadId to include all uploads.
2: return type is EventSubscription not void

Adds "@types/react-native": "^0.64.x" as a devDependency to get correct types for EventSubscription.

Examples of where these incorrect types causes issues:

1: Want to call addListener with null but get a typescript error

// TS error: Argument of type 'null' is not assignable to parameter of type 'string'. 
Upload.addListener('cancelled', null, () => {})

2: In an instance where a reference to the returned EventSubscription is desired a unsafe typecast workaround is required to get to the correct typing.
Current situation:

const subscription = (Upload.addListener('progress', uploadId, (response) => {
    ...
}) as unknown) as EventSubscription;

After fix:

const subscription = Upload.addListener('progress', uploadId, (response) => {...});

Also fixes link to the contributing doc from readme.

Test Plan

Verify addListener works as expected with updated types

Compatibility

OS Implemented
iOS
Android

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)
  • I've added Detox End-to-End Test(s)

README.md Outdated
@@ -313,7 +313,7 @@ Why should I use this file uploader instead of others that I've Googled like [re

# Contributing

See [CONTRIBUTING.md](https://github.com/Vydia/react-native-background-upload/CONTRIBUTING.md).
See [CONTRIBUTING.md](https://github.com/Vydia/react-native-background-upload/blob/master/CONTRIBUTING.md).
Copy link
Collaborator

Choose a reason for hiding this comment

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

just (./CONTRIBUTING.md)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 changed to ./CONTRIBUTING.md

Update the types to account for the following
1: Can be called with `null` to include all uploads
2: Returns an `EventSubscription` instead of void

Adds "@types/react-native": "^0.64.0" as a devDependency to get
the correct type for `EventSubscription`
@reime005 reime005 merged commit dc67c76 into Vydia:master May 5, 2021
github-actions bot pushed a commit that referenced this pull request May 5, 2021
## [6.2.2](v6.2.1...v6.2.2) (2021-05-05)

### Bug Fixes

* add listener types ([#246](#246)) ([dc67c76](dc67c76))
@github-actions
Copy link

github-actions bot commented May 5, 2021

🎉 This PR is included in version 6.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

benjamin777dev added a commit to benjamin777dev/react-native-upload that referenced this pull request Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants