mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 19:19:26 +08:00
fix: Upload data
type (#33193)
* fix: Upload `data` type * fix eslint errors
This commit is contained in:
parent
eb3cf792cf
commit
2df7cc6f30
@ -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,
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user