Open rexleimo opened 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';
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.
typscript how to use ?