diff --git a/components/upload/Upload.tsx b/components/upload/Upload.tsx index 23269c2446..db16e4bff9 100644 --- a/components/upload/Upload.tsx +++ b/components/upload/Upload.tsx @@ -174,13 +174,13 @@ const InternalUpload: React.ForwardRefRenderFunction = (pr let clone; try { - clone = (new File([originFileObj], originFileObj.name, { + clone = new File([originFileObj], originFileObj.name, { type: originFileObj.type, - }) as any) as UploadFile; + }) as any as UploadFile; } catch (e) { - clone = (new Blob([originFileObj], { + clone = new Blob([originFileObj], { type: originFileObj.type, - }) as any) as UploadFile; + }) as any as UploadFile; clone.name = originFileObj.name; clone.lastModifiedDate = new Date(); clone.lastModified = new Date().getTime(); @@ -305,7 +305,7 @@ const InternalUpload: React.ForwardRefRenderFunction = (pr onError, onProgress, onSuccess, - ...props, + ...(props as RcUploadProps), prefixCls, beforeUpload: mergedBeforeUpload, onChange: undefined, diff --git a/components/upload/__tests__/type.test.tsx b/components/upload/__tests__/type.test.tsx index f4b987309c..d3ce1cd3c0 100644 --- a/components/upload/__tests__/type.test.tsx +++ b/components/upload/__tests__/type.test.tsx @@ -99,11 +99,10 @@ describe('Upload.typescript', () => { status: 'error' as const, }, ]; - const upload = ( - - ) + const upload = ; expect(upload).toBeTruthy(); }); + it('itemRender', () => { const upload = ( { ); expect(upload).toBeTruthy(); }); + + it('data', () => { + const upload1 = ( + ({ + url: '', + })} + > + click to upload + + ); + const upload2 = ( + + Promise.resolve({ + url: '', + }) + } + > + click to upload + + ); + const upload3 = ( + + click to upload + + ); + expect(upload1).toBeTruthy(); + expect(upload2).toBeTruthy(); + expect(upload3).toBeTruthy(); + }); }); diff --git a/components/upload/interface.tsx b/components/upload/interface.tsx index 2aa11ae9e8..efd41d720a 100755 --- a/components/upload/interface.tsx +++ b/components/upload/interface.tsx @@ -90,7 +90,9 @@ export interface UploadProps { fileList?: Array>; action?: string | ((file: RcFile) => string) | ((file: RcFile) => PromiseLike); directory?: boolean; - data?: object | ((file: UploadFile) => object); + data?: + | Record + | ((file: UploadFile) => Record | Promise>); method?: 'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch'; headers?: HttpRequestHeader; showUploadList?: boolean | ShowUploadListInterface;