mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 14:13:37 +08:00
fix: Upload types for pass generic (#33543)
* fix: Upload types for pass generic * fix: Upload type * refactor: Upload type * feat: add Upload type test case
This commit is contained in:
parent
9a6ae9bb82
commit
8ebb4a3d23
@ -422,15 +422,20 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface CompoundedComponent
|
const ForwardUpload = React.forwardRef<unknown, UploadProps>(InternalUpload) as <T>(
|
||||||
extends React.ForwardRefExoticComponent<
|
props: React.PropsWithChildren<UploadProps<T>> & React.RefAttributes<any>,
|
||||||
React.PropsWithChildren<UploadProps> & React.RefAttributes<any>
|
) => React.ReactElement;
|
||||||
> {
|
|
||||||
|
type InternalUploadType = typeof ForwardUpload;
|
||||||
|
|
||||||
|
interface UploadInterface extends InternalUploadType {
|
||||||
|
defaultProps?: Partial<UploadProps>;
|
||||||
|
displayName?: string;
|
||||||
Dragger: typeof Dragger;
|
Dragger: typeof Dragger;
|
||||||
LIST_IGNORE: string;
|
LIST_IGNORE: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Upload = React.forwardRef<unknown, UploadProps>(InternalUpload) as CompoundedComponent;
|
const Upload = ForwardUpload as UploadInterface;
|
||||||
|
|
||||||
Upload.Dragger = Dragger;
|
Upload.Dragger = Dragger;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Upload from '..';
|
import Upload, { UploadProps } from '..';
|
||||||
|
|
||||||
describe('Upload.typescript', () => {
|
describe('Upload.typescript', () => {
|
||||||
it('Upload', () => {
|
it('Upload', () => {
|
||||||
@ -11,6 +11,29 @@ describe('Upload.typescript', () => {
|
|||||||
expect(upload).toBeTruthy();
|
expect(upload).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('onChange', () => {
|
||||||
|
const upload = (
|
||||||
|
<Upload<File> onChange={({ file }) => file}>
|
||||||
|
<span>click to upload</span>
|
||||||
|
</Upload>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(upload).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('onChange in UploadProps', () => {
|
||||||
|
const uploadProps: UploadProps<File> = {
|
||||||
|
onChange: ({ file }) => file,
|
||||||
|
};
|
||||||
|
const upload = (
|
||||||
|
<Upload {...uploadProps}>
|
||||||
|
<span>click to upload</span>
|
||||||
|
</Upload>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(upload).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
it('showUploadList', () => {
|
it('showUploadList', () => {
|
||||||
const upload = (
|
const upload = (
|
||||||
<Upload
|
<Upload
|
||||||
|
@ -40,7 +40,7 @@ export interface InternalUploadFile<T = any> extends UploadFile<T> {
|
|||||||
originFileObj: RcFile;
|
originFileObj: RcFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UploadChangeParam<T extends object = UploadFile> {
|
export interface UploadChangeParam<T = UploadFile> {
|
||||||
// https://github.com/ant-design/ant-design/issues/14420
|
// https://github.com/ant-design/ant-design/issues/14420
|
||||||
file: T;
|
file: T;
|
||||||
fileList: UploadFile[];
|
fileList: UploadFile[];
|
||||||
@ -104,7 +104,7 @@ export interface UploadProps<T = any> extends Pick<RcUploadProps, 'capture'> {
|
|||||||
file: RcFile,
|
file: RcFile,
|
||||||
FileList: RcFile[],
|
FileList: RcFile[],
|
||||||
) => BeforeUploadValueType | Promise<BeforeUploadValueType>;
|
) => BeforeUploadValueType | Promise<BeforeUploadValueType>;
|
||||||
onChange?: (info: UploadChangeParam) => void;
|
onChange?: (info: UploadChangeParam<T>) => void;
|
||||||
onDrop?: (event: React.DragEvent<HTMLDivElement>) => void;
|
onDrop?: (event: React.DragEvent<HTMLDivElement>) => void;
|
||||||
listType?: UploadListType;
|
listType?: UploadListType;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user