react-component / upload

React Upload
https://upload.react-component.vercel.app/
MIT License
776 stars 317 forks source link

typscript how to use ? #126

Open rexleimo opened 5 years ago

rexleimo commented 5 years ago

typscript how to use ?

richard-ejem commented 5 years ago

Like any other npm package that have no type definitions available, add a .d.ts file, for example rc-upload.d.ts (no need to import, typescript crawls .d.ts automatically) and put this into the file: declare module 'rc-upload';

italodeandra commented 4 years ago

Example of the file for anyone who comes here in the future:

declare module 'rc-upload' {

    import { PropsWithChildren, CSSProperties, HTMLAttributes } from 'react'

    interface Headers {
        [key: string]: any
    }

    interface Data {
        [key: string]: any
    }

    type PromiseRejection = Promise

    interface UploadProps {
        name?: string = 'file'
        style?: CSSProperties
        className?: string
        disabled?: boolean
        component?: string = 'span'
        onReady?: () => void
        action?: string | ((file: File) => string) | Promise<string>
        method?: string = 'post'
        directory?: boolean
        data?: Data | (() => Data)
        headers?: Headers
        accept?: string
        multiple?: boolean
        onStart?: () => void
        onError?: (error: any, response: any, file: File) => void
        onSuccess?: (response: any, file: File, xhr: any) => void
        onProgress?: (step: any, file: File) => void
        beforeUpload?: (file: File) => false | PromiseRejection
        customRequest?: Function
        withCredentials?: boolean
        openFileDialogOnClick?: boolean = true
        transformFile?: (file: File) => Promise<Blob>
        type?: string
    }

    export default function Upload(props: UploadProps & PropsWithChildren<HTMLAttributes>): JSX.Element

}

Warning: I'm not using rc-upload anymore, so I didn't test that much, there might be mistakes.