fix: Upload data type (#33193)

* fix: Upload `data` type

* fix eslint errors
This commit is contained in:
afc163 2021-12-07 21:45:11 +08:00 committed by GitHub
parent eb3cf792cf
commit 2df7cc6f30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 9 deletions

View File

@ -174,13 +174,13 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (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<unknown, UploadProps> = (pr
onError,
onProgress,
onSuccess,
...props,
...(props as RcUploadProps),
prefixCls,
beforeUpload: mergedBeforeUpload,
onChange: undefined,

View File

@ -99,11 +99,10 @@ describe('Upload.typescript', () => {
status: 'error' as const,
},
];
const upload = (
<Upload fileList={fileList} defaultFileList={fileList} />
)
const upload = <Upload fileList={fileList} defaultFileList={fileList} />;
expect(upload).toBeTruthy();
});
it('itemRender', () => {
const upload = (
<Upload
@ -123,4 +122,39 @@ describe('Upload.typescript', () => {
);
expect(upload).toBeTruthy();
});
it('data', () => {
const upload1 = (
<Upload
data={() => ({
url: '',
})}
>
<span>click to upload</span>
</Upload>
);
const upload2 = (
<Upload
data={() =>
Promise.resolve({
url: '',
})
}
>
<span>click to upload</span>
</Upload>
);
const upload3 = (
<Upload
data={{
url: '',
}}
>
<span>click to upload</span>
</Upload>
);
expect(upload1).toBeTruthy();
expect(upload2).toBeTruthy();
expect(upload3).toBeTruthy();
});
});

View File

@ -90,7 +90,9 @@ export interface UploadProps<T = any> {
fileList?: Array<UploadFile<T>>;
action?: string | ((file: RcFile) => string) | ((file: RcFile) => PromiseLike<string>);
directory?: boolean;
data?: object | ((file: UploadFile<T>) => object);
data?:
| Record<string, unknown>
| ((file: UploadFile<T>) => Record<string, unknown> | Promise<Record<string, unknown>>);
method?: 'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch';
headers?: HttpRequestHeader;
showUploadList?: boolean | ShowUploadListInterface;