Skip to content

Commit

Permalink
fix: add listener types (#246)
Browse files Browse the repository at this point in the history
* Fix types for addListener

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`

* Fix broken link to CONTRIBUTING.MD
  • Loading branch information
Mookiies authored May 5, 2021
1 parent ec141a2 commit dc67c76
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](./CONTRIBUTING.md).

# Common Issues

Expand Down
9 changes: 5 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module "react-native-background-upload" {
import type { EventSubscription } from 'react-native';

export interface EventData {
id: string;
Expand Down Expand Up @@ -112,10 +113,10 @@ declare module "react-native-background-upload" {

export default class Upload {
static startUpload(options: UploadOptions | MultipartUploadOptions): Promise<uploadId>
static addListener(event: 'progress', uploadId: uploadId, callback: (data: ProgressData ) => void): void
static addListener(event: 'error', uploadId: uploadId, callback: (data: ErrorData) => void): void
static addListener(event: 'completed', uploadId: uploadId, callback: (data: CompletedData) => void): void
static addListener(event: 'cancelled', uploadId: uploadId, callback: (data: EventData) => void): void
static addListener(event: 'progress', uploadId: uploadId | null, callback: (data: ProgressData ) => void): EventSubscription
static addListener(event: 'error', uploadId: uploadId | null, callback: (data: ErrorData) => void): EventSubscription
static addListener(event: 'completed', uploadId: uploadId | null, callback: (data: CompletedData) => void): EventSubscription
static addListener(event: 'cancelled', uploadId: uploadId | null, callback: (data: EventData) => void): EventSubscription
static getFileInfo(path: string): Promise<FileInfo>
static cancelUpload(uploadId: uploadId): Promise<boolean>
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@semantic-release/github": "^5.5.5",
"@semantic-release/npm": "^5.3.4",
"@semantic-release/release-notes-generator": "^7.3.5",
"@types/react-native": "^0.64.0",
"eslint": "^6.8.0",
"husky": "^4.2.3",
"lint-staged": "^10.0.8",
Expand Down
31 changes: 31 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,37 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/prop-types@*":
version "15.7.3"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==

"@types/react-native@^0.64.0":
version "0.64.4"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.64.4.tgz#9f11bef7dd5520801884829c73b19d75aa42e73c"
integrity sha512-VqnlmadGkD5usREvnuyVpWDS1W8f6cCz6MP5fZdgONsaZ9/Ijfb9Iq9MZ5O3bnW1OyJixDX9HtSp3COsFSLD8Q==
dependencies:
"@types/react" "*"

"@types/react@*":
version "17.0.3"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.3.tgz#ba6e215368501ac3826951eef2904574c262cc79"
integrity sha512-wYOUxIgs2HZZ0ACNiIayItyluADNbONl7kt8lkLjVK8IitMH5QMyAh75Fwhmo37r1m7L2JaFj03sIfxBVDvRAg==
dependencies:
"@types/prop-types" "*"
"@types/scheduler" "*"
csstype "^3.0.2"

"@types/retry@^0.12.0":
version "0.12.0"
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==

"@types/scheduler@*":
version "0.16.1"
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275"
integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==

"@typescript-eslint/eslint-plugin@^1.5.0":
version "1.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.13.0.tgz#22fed9b16ddfeb402fd7bcde56307820f6ebc49f"
Expand Down Expand Up @@ -1232,6 +1258,11 @@ crypto-random-string@^1.0.0:
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=

csstype@^3.0.2:
version "3.0.8"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.8.tgz#d2266a792729fb227cd216fb572f43728e1ad340"
integrity sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==

currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"
Expand Down

0 comments on commit dc67c76

Please sign in to comment.