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
|
||||
extends React.ForwardRefExoticComponent<
|
||||
React.PropsWithChildren<UploadProps> & React.RefAttributes<any>
|
||||
> {
|
||||
const ForwardUpload = React.forwardRef<unknown, UploadProps>(InternalUpload) as <T>(
|
||||
props: React.PropsWithChildren<UploadProps<T>> & React.RefAttributes<any>,
|
||||
) => React.ReactElement;
|
||||
|
||||
type InternalUploadType = typeof ForwardUpload;
|
||||
|
||||
interface UploadInterface extends InternalUploadType {
|
||||
defaultProps?: Partial<UploadProps>;
|
||||
displayName?: string;
|
||||
Dragger: typeof Dragger;
|
||||
LIST_IGNORE: string;
|
||||
}
|
||||
|
||||
const Upload = React.forwardRef<unknown, UploadProps>(InternalUpload) as CompoundedComponent;
|
||||
const Upload = ForwardUpload as UploadInterface;
|
||||
|
||||
Upload.Dragger = Dragger;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import Upload from '..';
|
||||
import Upload, { UploadProps } from '..';
|
||||
|
||||
describe('Upload.typescript', () => {
|
||||
it('Upload', () => {
|
||||
@ -11,6 +11,29 @@ describe('Upload.typescript', () => {
|
||||
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', () => {
|
||||
const upload = (
|
||||
<Upload
|
||||
|
@ -40,7 +40,7 @@ export interface InternalUploadFile<T = any> extends UploadFile<T> {
|
||||
originFileObj: RcFile;
|
||||
}
|
||||
|
||||
export interface UploadChangeParam<T extends object = UploadFile> {
|
||||
export interface UploadChangeParam<T = UploadFile> {
|
||||
// https://github.com/ant-design/ant-design/issues/14420
|
||||
file: T;
|
||||
fileList: UploadFile[];
|
||||
@ -104,7 +104,7 @@ export interface UploadProps<T = any> extends Pick<RcUploadProps, 'capture'> {
|
||||
file: RcFile,
|
||||
FileList: RcFile[],
|
||||
) => BeforeUploadValueType | Promise<BeforeUploadValueType>;
|
||||
onChange?: (info: UploadChangeParam) => void;
|
||||
onChange?: (info: UploadChangeParam<T>) => void;
|
||||
onDrop?: (event: React.DragEvent<HTMLDivElement>) => void;
|
||||
listType?: UploadListType;
|
||||
className?: string;
|
||||
|
Loading…
Reference in New Issue
Block a user