mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 20:19:44 +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;
|
let clone;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
clone = (new File([originFileObj], originFileObj.name, {
|
clone = new File([originFileObj], originFileObj.name, {
|
||||||
type: originFileObj.type,
|
type: originFileObj.type,
|
||||||
}) as any) as UploadFile;
|
}) as any as UploadFile;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
clone = (new Blob([originFileObj], {
|
clone = new Blob([originFileObj], {
|
||||||
type: originFileObj.type,
|
type: originFileObj.type,
|
||||||
}) as any) as UploadFile;
|
}) as any as UploadFile;
|
||||||
clone.name = originFileObj.name;
|
clone.name = originFileObj.name;
|
||||||
clone.lastModifiedDate = new Date();
|
clone.lastModifiedDate = new Date();
|
||||||
clone.lastModified = new Date().getTime();
|
clone.lastModified = new Date().getTime();
|
||||||
@ -305,7 +305,7 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
|
|||||||
onError,
|
onError,
|
||||||
onProgress,
|
onProgress,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
...props,
|
...(props as RcUploadProps),
|
||||||
prefixCls,
|
prefixCls,
|
||||||
beforeUpload: mergedBeforeUpload,
|
beforeUpload: mergedBeforeUpload,
|
||||||
onChange: undefined,
|
onChange: undefined,
|
||||||
|
@ -99,11 +99,10 @@ describe('Upload.typescript', () => {
|
|||||||
status: 'error' as const,
|
status: 'error' as const,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const upload = (
|
const upload = <Upload fileList={fileList} defaultFileList={fileList} />;
|
||||||
<Upload fileList={fileList} defaultFileList={fileList} />
|
|
||||||
)
|
|
||||||
expect(upload).toBeTruthy();
|
expect(upload).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('itemRender', () => {
|
it('itemRender', () => {
|
||||||
const upload = (
|
const upload = (
|
||||||
<Upload
|
<Upload
|
||||||
@ -123,4 +122,39 @@ describe('Upload.typescript', () => {
|
|||||||
);
|
);
|
||||||
expect(upload).toBeTruthy();
|
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>>;
|
fileList?: Array<UploadFile<T>>;
|
||||||
action?: string | ((file: RcFile) => string) | ((file: RcFile) => PromiseLike<string>);
|
action?: string | ((file: RcFile) => string) | ((file: RcFile) => PromiseLike<string>);
|
||||||
directory?: boolean;
|
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';
|
method?: 'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch';
|
||||||
headers?: HttpRequestHeader;
|
headers?: HttpRequestHeader;
|
||||||
showUploadList?: boolean | ShowUploadListInterface;
|
showUploadList?: boolean | ShowUploadListInterface;
|
||||||
|
Loading…
Reference in New Issue
Block a user