Skip to content

Commit

Permalink
fix: tsc noEmit (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Layouwen authored Aug 18, 2024
1 parent b3d0cdd commit 394f03c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/examples/asyncAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Upload from 'rc-upload';

const props = {
action: () => {
return new Promise(resolve => {
return new Promise<string>(resolve => {
setTimeout(() => {
resolve('/upload.do');
}, 2000);
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/beforeUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint no-console:0 */

import React from 'react';
import { Action } from '@/interface';
import Upload from 'rc-upload';

const props = {
action: '/upload.do',
action: '/upload.do' as Action,
multiple: true,
onStart(file) {
console.log('onStart', file, file.name);
Expand All @@ -17,7 +17,7 @@ const props = {
},
beforeUpload(file, fileList) {
console.log(file, fileList);
return new Promise(resolve => {
return new Promise<string>(resolve => {
console.log('start check');
setTimeout(() => {
console.log('check finshed');
Expand Down
7 changes: 4 additions & 3 deletions docs/examples/customRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';
import axios from 'axios';
import Upload from 'rc-upload';
import { UploadRequestOption } from '@/interface';

const uploadProps = {
action: '/upload.do',
Expand Down Expand Up @@ -32,13 +33,13 @@ const uploadProps = {
onProgress,
onSuccess,
withCredentials,
}) {
}: UploadRequestOption) {
// EXAMPLE: post form-data with 'axios'
// eslint-disable-next-line no-undef
const formData = new FormData();
if (data) {
Object.keys(data).forEach(key => {
formData.append(key, data[key]);
formData.append(key, data[key] as string);
});
}
formData.append(filename, file);
Expand All @@ -48,7 +49,7 @@ const uploadProps = {
withCredentials,
headers,
onUploadProgress: ({ total, loaded }) => {
onProgress({ percent: Math.round((loaded / total) * 100).toFixed(2) }, file);
onProgress({ percent: Number(Math.round((loaded / total) * 100).toFixed(2)) }, file);
},
})
.then(({ data: response }) => {
Expand Down
10 changes: 6 additions & 4 deletions src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface UploadProps
file: RcFile,
FileList: RcFile[],
) => BeforeUploadFileType | Promise<void | BeforeUploadFileType> | void;
customRequest?: (option: UploadRequestOption) => void;
customRequest?: (option: UploadRequestOption) => void | { abort: () => void };
withCredentials?: boolean;
openFileDialogOnClick?: boolean;
prefixCls?: string;
Expand All @@ -54,19 +54,21 @@ export type UploadRequestMethod = 'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'p

export type UploadRequestHeader = Record<string, string>;

export type UploadRequestFile = Exclude<BeforeUploadFileType, File | boolean> | RcFile;

export interface UploadRequestError extends Error {
status?: number;
method?: UploadRequestMethod;
url?: string;
}

export interface UploadRequestOption<T = any> {
onProgress?: (event: UploadProgressEvent) => void;
onProgress?: (event: UploadProgressEvent, file?: UploadRequestFile) => void;
onError?: (event: UploadRequestError | ProgressEvent, body?: T) => void;
onSuccess?: (body: T, xhr?: XMLHttpRequest) => void;
onSuccess?: (body: T, fileOrXhr?: UploadRequestFile | XMLHttpRequest) => void;
data?: Record<string, unknown>;
filename?: string;
file: Exclude<BeforeUploadFileType, File | boolean> | RcFile;
file: UploadRequestFile;
withCredentials?: boolean;
action: string;
headers?: UploadRequestHeader;
Expand Down

0 comments on commit 394f03c

Please sign in to comment.