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

Add index.d.ts file with Typescript bindings #182

Merged
merged 1 commit into from
Apr 1, 2020
Merged

Add index.d.ts file with Typescript bindings #182

merged 1 commit into from
Apr 1, 2020

Conversation

Palid
Copy link
Contributor

@Palid Palid commented Jan 21, 2020

A lot of projects are using Typescript now and this package doesn't have it's own separate @types package, so I just wrote types for this one. You're welcome! :)

Copy link
Contributor

@reime005 reime005 left a comment

Choose a reason for hiding this comment

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

cool, thx!

@reime005 reime005 merged commit 11fdb8b into Vydia:master Apr 1, 2020
github-actions bot pushed a commit that referenced this pull request Apr 1, 2020
# [5.5.0](v5.4.0...v5.5.0) (2020-04-01)

### Features

* add index.d.ts file with Typescript bindings ([#182](#182)) ([11fdb8b](11fdb8b))
@github-actions
Copy link

github-actions bot commented Apr 1, 2020

🎉 This PR is included in version 5.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sammarks
Copy link

sammarks commented Jun 5, 2020

Heads up, I think these typings are wrong. I'm using version 5.4.0 with my own custom types, and upgrading to >= 5.5.0 completely breaks the usage.

I'm not putting up a separate PR because my types aren't complete, but here were my types for reference:

declare module 'react-native-background-upload' {
  // We're not using this for now, so will always be enabled: false.
  import { EventSubscription } from 'react-native'

  export interface AndroidNotificationOptions {
    enabled?: boolean
    onProgressTitle?: string
    autoClear?: true
  }
  export interface UploadOptions {
    url: string
    path: string
    method: string
    type: 'raw' | 'multipart'
    maxRetries?: number
    headers?: {
      [header: string]: string
    }
    field?: string
    parameters?: {
      [param: string]: string
    }
    notification?: AndroidNotificationOptions
    useUtf8Charset?: boolean
  }
  export interface ProgressData {
    id: string
    // From 0 - 100, not a decimal.
    progress: number
  }
  export interface ErrorData {
    id: string
    error: Error
  }
  export interface CompleteData {
    id: string
    responseCode: number
    responseBody: object
  }
  export interface CancelledData {
    id: string
  }
  export function startUpload(options: UploadOptions): Promise<string>
  export function addListener(
    event: 'progress',
    uploadId: string | null,
    callback: (data: ProgressData) => any,
  ): EventSubscription
  export function addListener(
    event: 'error',
    uploadId: string | null,
    callback: (data: ErrorData) => any,
  ): EventSubscription
  export function addListener(
    event: 'cancelled',
    uploadId: string | null,
    callback: (data: CancelledData) => any,
  ): EventSubscription
  export function addListener(
    event: 'completed',
    uploadId: string | null,
    callback: (data: CompleteData) => any,
  ): EventSubscription
  export function cancelUpload(uploadId: string): Promise<boolean>
  export type FileInfo =
    | {
        name: string
        exists: boolean
      }
    | {
        exists: true
        size: number
        extension: string
        mimeType: string
      }
  export function getFileInfo(path: string): Promise<FileInfo>
}

Is there anything obviously wrong with mine? Don't seem to cause any runtime errors when following these typings.

@Palid
Copy link
Contributor Author

Palid commented Jun 7, 2020

@sammarks what's wrong with those typings after upgrade? From what I see in the typings you have provided, mine are missing a couple of fields. Is that the case? If that's the case, could you kindly make a pull request with the missing fields that break on your side?

@Palid Palid deleted the patch-2 branch June 7, 2020 12:03
@Palid
Copy link
Contributor Author

Palid commented Jun 8, 2020

@sammarks Additionally fixed in #198

@sammarks
Copy link

sammarks commented Jun 8, 2020

@Palid the most notable change is the addListener() functions don't include a reference to a callback function but instead look like they contain part of the definition for the callback function instead.

@Palid
Copy link
Contributor Author

Palid commented Jun 8, 2020

@sammarks you're right! Haven't noticed that, will do the changes too in my PR. :)

@Palid
Copy link
Contributor Author

Palid commented Jun 8, 2020

@sammarks I think you can safely use 9eb55a5 temporarily until it gets merged. Thanks for letting me know! Those types were only 'working' because I accidentally added static addListener(event: UploadListenerEvent, uploadId: uploadId, callback: (data: object) => void ): void in there which was pretty much a catchall. Good catch!

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.

3 participants