diff --git a/components/upload/Upload.tsx b/components/upload/Upload.tsx index 013fba696e..628f36afd8 100644 --- a/components/upload/Upload.tsx +++ b/components/upload/Upload.tsx @@ -422,15 +422,20 @@ const InternalUpload: React.ForwardRefRenderFunction = (pr ); }; -interface CompoundedComponent - extends React.ForwardRefExoticComponent< - React.PropsWithChildren & React.RefAttributes - > { +const ForwardUpload = React.forwardRef(InternalUpload) as ( + props: React.PropsWithChildren> & React.RefAttributes, +) => React.ReactElement; + +type InternalUploadType = typeof ForwardUpload; + +interface UploadInterface extends InternalUploadType { + defaultProps?: Partial; + displayName?: string; Dragger: typeof Dragger; LIST_IGNORE: string; } -const Upload = React.forwardRef(InternalUpload) as CompoundedComponent; +const Upload = ForwardUpload as UploadInterface; Upload.Dragger = Dragger; diff --git a/components/upload/__tests__/type.test.tsx b/components/upload/__tests__/type.test.tsx index d3ce1cd3c0..ffd297b30c 100644 --- a/components/upload/__tests__/type.test.tsx +++ b/components/upload/__tests__/type.test.tsx @@ -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 = ( + onChange={({ file }) => file}> + click to upload + + ); + + expect(upload).toBeTruthy(); + }); + + it('onChange in UploadProps', () => { + const uploadProps: UploadProps = { + onChange: ({ file }) => file, + }; + const upload = ( + + click to upload + + ); + + expect(upload).toBeTruthy(); + }); + it('showUploadList', () => { const upload = ( extends UploadFile { originFileObj: RcFile; } -export interface UploadChangeParam { +export interface UploadChangeParam { // https://github.com/ant-design/ant-design/issues/14420 file: T; fileList: UploadFile[]; @@ -104,7 +104,7 @@ export interface UploadProps extends Pick { file: RcFile, FileList: RcFile[], ) => BeforeUploadValueType | Promise; - onChange?: (info: UploadChangeParam) => void; + onChange?: (info: UploadChangeParam) => void; onDrop?: (event: React.DragEvent) => void; listType?: UploadListType; className?: string;