Browse Source

fix(upload): UploadFile type definition (#30343)

pull/30354/head
Kermit 4 years ago
committed by GitHub
parent
commit
4ccbf1fd0f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      components/upload/UploadList/index.tsx
  2. 23
      components/upload/__tests__/type.test.tsx
  3. 15
      components/upload/interface.tsx
  4. 4
      components/upload/utils.tsx

4
components/upload/UploadList/index.tsx

@ -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' ||

23
components/upload/__tests__/type.test.tsx

@ -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();
});
});

15
components/upload/interface.tsx

@ -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;

4
components/upload/utils.tsx

@ -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…
Cancel
Save