Browse Source

type: update type unknown with UploadRef (#42985)

* type: update type unknown with UploadRef

* type: fix type
pull/42990/head
lijianan 1 year ago
committed by GitHub
parent
commit
1d1f4efcf4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      components/upload/Dragger.tsx
  2. 22
      components/upload/Upload.tsx

11
components/upload/Dragger.tsx

@ -1,12 +1,15 @@
import * as React from 'react';
import type { UploadProps } from './interface';
import type { UploadRef } from './Upload';
import Upload from './Upload';
import type { UploadProps } from './interface';
export type DraggerProps = UploadProps & { height?: number };
const Dragger = React.forwardRef<unknown, DraggerProps>(({ style, height, ...restProps }, ref) => (
<Upload ref={ref} {...restProps} type="drag" style={{ ...style, height }} />
));
const Dragger = React.forwardRef<UploadRef, DraggerProps>(
({ style, height, ...restProps }, ref) => (
<Upload ref={ref} {...restProps} type="drag" style={{ ...style, height }} />
),
);
if (process.env.NODE_ENV !== 'production') {
Dragger.displayName = 'Dragger';

22
components/upload/Upload.tsx

@ -4,11 +4,12 @@ import RcUpload from 'rc-upload';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import * as React from 'react';
import { flushSync } from 'react-dom';
import warning from '../_util/warning';
import { ConfigContext } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import defaultLocale from '../locale/en_US';
import { useLocale } from '../locale';
import warning from '../_util/warning';
import defaultLocale from '../locale/en_US';
import UploadList from './UploadList';
import type {
RcFile,
ShowUploadListInterface,
@ -16,16 +17,23 @@ import type {
UploadFile,
UploadProps,
} from './interface';
import UploadList from './UploadList';
import { file2Obj, getFileItem, removeFileItem, updateFileList } from './utils';
import useStyle from './style';
import { file2Obj, getFileItem, removeFileItem, updateFileList } from './utils';
export const LIST_IGNORE = `__LIST_IGNORE_${Date.now()}__`;
export type { UploadProps };
const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (props, ref) => {
export interface UploadRef<T = any> {
onBatchStart: RcUploadProps['onBatchStart'];
onSuccess: (response: any, file: RcFile, xhr: any) => void;
onProgress: (e: { percent: number }, file: RcFile) => void;
onError: (error: Error, response: any, file: RcFile) => void;
fileList: UploadFile<T>[];
upload: RcUpload | null;
}
const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (props, ref) => {
const {
fileList,
defaultFileList,
@ -461,7 +469,7 @@ const InternalUpload: React.ForwardRefRenderFunction<unknown, UploadProps> = (pr
);
};
const Upload = React.forwardRef<unknown, UploadProps>(InternalUpload);
const Upload = React.forwardRef<UploadRef, UploadProps>(InternalUpload);
if (process.env.NODE_ENV !== 'production') {
Upload.displayName = 'Upload';

Loading…
Cancel
Save