itinance / itinance/react-native-fs

`downloadFile`: Make type of `begin` required when `progress` is used

Open
#1,118 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used [patch-package](https://github.com/ds300/patch-package) to patch `react-native-fs@2.20.0` for the project I'm working on.

Related to: https://github.com/itinance/react-native-fs/issues/760

Here is the diff that solved my problem:

```diff
diff --git a/node_modules/react-native-fs/index.d.ts b/node_modules/react-native-fs/index.d.ts
index da3fa7d..aa99cd0 100644
--- a/node_modules/react-native-fs/index.d.ts
+++ b/node_modules/react-native-fs/index.d.ts
@@ -41,13 +41,17 @@ type DownloadFileOptions = {
cacheable?: boolean // Whether the download can be stored in the shared NSURLCache (iOS only)
progressInterval?: number
progressDivider?: number
- begin?: (res: DownloadBeginCallbackResult) => void
- progress?: (res: DownloadProgressCallbackResult) => void
resumable?: () => void // only supported on iOS yet
connectionTimeout?: number // only supported on Android yet
readTimeout?: number // supported on Android and iOS
backgroundTimeout?: number // Maximum time (in milliseconds) to download an entire resource (iOS only, useful for timing out background downloads)
-}
+} & ({
+ begin: (res: DownloadBeginCallbackResult) => void;
+ progress: (res: DownloadProgressCallbackResult) => void;
+ } | {
+ begin?: (res: DownloadBeginCallbackResult) => void;
+ progress?: undefined;
+ })

type DownloadBeginCallbackResult = {
jobId: number // The download job ID, required if one wishes to cancel the download. See `stopDownload`.
```

This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.