mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
fix(upload): UploadFile type definition (#30343)
This commit is contained in:
parent
fa80ae5a0a
commit
4ccbf1fd0f
@ -6,7 +6,7 @@ import PaperClipOutlined from '@ant-design/icons/PaperClipOutlined';
|
||||
import PictureTwoTone from '@ant-design/icons/PictureTwoTone';
|
||||
import FileTwoTone from '@ant-design/icons/FileTwoTone';
|
||||
import { cloneElement, isValidElement } from '../../_util/reactNode';
|
||||
import { UploadListProps, UploadFile, UploadListType } from '../interface';
|
||||
import { UploadListProps, UploadFile, UploadListType, InternalUploadFile } from '../interface';
|
||||
import { previewImage, isImageUrl } from '../utils';
|
||||
import collapseMotion from '../../_util/motion';
|
||||
import { ConfigContext } from '../../config-provider';
|
||||
@ -53,7 +53,7 @@ const InternalUploadList: React.ForwardRefRenderFunction<unknown, UploadListProp
|
||||
if (listType !== 'picture' && listType !== 'picture-card') {
|
||||
return;
|
||||
}
|
||||
(items || []).forEach(file => {
|
||||
(items || []).forEach((file: InternalUploadFile) => {
|
||||
if (
|
||||
typeof document === 'undefined' ||
|
||||
typeof window === 'undefined' ||
|
||||
|
@ -46,4 +46,27 @@ describe('Upload.typescript', () => {
|
||||
);
|
||||
expect(upload).toBeTruthy();
|
||||
});
|
||||
|
||||
it('defaultFileList/fileList', () => {
|
||||
const fileList = [
|
||||
{
|
||||
uid: '-1',
|
||||
name: 'xxx.png',
|
||||
status: 'done' as const,
|
||||
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
|
||||
},
|
||||
{
|
||||
uid: '-2',
|
||||
name: 'yyy.png',
|
||||
status: 'error' as const,
|
||||
},
|
||||
];
|
||||
const upload = (
|
||||
<Upload fileList={fileList} defaultFileList={fileList}>
|
||||
<span>click to upload</span>
|
||||
</Upload>
|
||||
);
|
||||
expect(upload).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ export interface HttpRequestHeader {
|
||||
|
||||
export interface UploadFile<T = any> {
|
||||
uid: string;
|
||||
size: number;
|
||||
size?: number;
|
||||
name: string;
|
||||
fileName?: string;
|
||||
lastModified?: number;
|
||||
@ -26,15 +26,19 @@ export interface UploadFile<T = any> {
|
||||
status?: UploadFileStatus;
|
||||
percent?: number;
|
||||
thumbUrl?: string;
|
||||
originFileObj: RcFile;
|
||||
originFileObj?: RcFile;
|
||||
response?: T;
|
||||
error?: any;
|
||||
linkProps?: any;
|
||||
type: string;
|
||||
type?: string;
|
||||
xhr?: T;
|
||||
preview?: string;
|
||||
}
|
||||
|
||||
export interface InternalUploadFile<T = any> extends UploadFile<T> {
|
||||
originFileObj: RcFile;
|
||||
}
|
||||
|
||||
export interface UploadChangeParam<T extends object = UploadFile> {
|
||||
// https://github.com/ant-design/ant-design/issues/14420
|
||||
file: T;
|
||||
@ -86,7 +90,10 @@ export interface UploadProps<T = any> {
|
||||
showUploadList?: boolean | ShowUploadListInterface;
|
||||
multiple?: boolean;
|
||||
accept?: string;
|
||||
beforeUpload?: (file: RcFile, FileList: RcFile[]) => boolean | string | Promise<void | Blob | File>;
|
||||
beforeUpload?: (
|
||||
file: RcFile,
|
||||
FileList: RcFile[],
|
||||
) => boolean | string | Promise<void | Blob | File>;
|
||||
onChange?: (info: UploadChangeParam) => void;
|
||||
listType?: UploadListType;
|
||||
className?: string;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { RcFile, UploadFile } from './interface';
|
||||
import { RcFile, UploadFile, InternalUploadFile } from './interface';
|
||||
|
||||
export function file2Obj(file: RcFile): UploadFile {
|
||||
export function file2Obj(file: RcFile): InternalUploadFile {
|
||||
return {
|
||||
...file,
|
||||
lastModified: file.lastModified,
|
||||
|
Loading…
Reference in New Issue
Block a user