Vydia / react-native-background-upload

Upload files in your React Native app even while it's backgrounded. Supports Android and iOS, including camera roll assets.
MIT License
723 stars 330 forks source link

Fix add listener types #246

Closed Mookiies closed 3 years ago

Mookiies commented 3 years ago

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

github-actions[bot] commented 3 years ago

:tada: This PR is included in version 6.2.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: