-
Notifications
You must be signed in to change notification settings - Fork 341
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, thx!
# [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))
🎉 This PR is included in version 5.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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. |
@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 the most notable change is the |
@sammarks you're right! Haven't noticed that, will do the changes too in my PR. :) |
@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 |
# [5.5.0](Vydia/react-native-background-upload@v5.4.0...v5.5.0) (2020-04-01) ### Features * add index.d.ts file with Typescript bindings ([#182](Vydia/react-native-background-upload#182)) ([11fdb8b](Vydia/react-native-background-upload@11fdb8b))
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! :)