Skip to content

Commit 394f03c

Browse files
authored
fix: tsc noEmit (#570)
1 parent b3d0cdd commit 394f03c

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

docs/examples/asyncAction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Upload from 'rc-upload';
44

55
const props = {
66
action: () => {
7-
return new Promise(resolve => {
7+
return new Promise<string>(resolve => {
88
setTimeout(() => {
99
resolve('/upload.do');
1010
}, 2000);

docs/examples/beforeUpload.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint no-console:0 */
22

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

66
const props = {
7-
action: '/upload.do',
7+
action: '/upload.do' as Action,
88
multiple: true,
99
onStart(file) {
1010
console.log('onStart', file, file.name);
@@ -17,7 +17,7 @@ const props = {
1717
},
1818
beforeUpload(file, fileList) {
1919
console.log(file, fileList);
20-
return new Promise(resolve => {
20+
return new Promise<string>(resolve => {
2121
console.log('start check');
2222
setTimeout(() => {
2323
console.log('check finshed');

docs/examples/customRequest.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react';
33
import axios from 'axios';
44
import Upload from 'rc-upload';
5+
import { UploadRequestOption } from '@/interface';
56

67
const uploadProps = {
78
action: '/upload.do',
@@ -32,13 +33,13 @@ const uploadProps = {
3233
onProgress,
3334
onSuccess,
3435
withCredentials,
35-
}) {
36+
}: UploadRequestOption) {
3637
// EXAMPLE: post form-data with 'axios'
3738
// eslint-disable-next-line no-undef
3839
const formData = new FormData();
3940
if (data) {
4041
Object.keys(data).forEach(key => {
41-
formData.append(key, data[key]);
42+
formData.append(key, data[key] as string);
4243
});
4344
}
4445
formData.append(filename, file);
@@ -48,7 +49,7 @@ const uploadProps = {
4849
withCredentials,
4950
headers,
5051
onUploadProgress: ({ total, loaded }) => {
51-
onProgress({ percent: Math.round((loaded / total) * 100).toFixed(2) }, file);
52+
onProgress({ percent: Number(Math.round((loaded / total) * 100).toFixed(2)) }, file);
5253
},
5354
})
5455
.then(({ data: response }) => {

src/interface.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface UploadProps
2929
file: RcFile,
3030
FileList: RcFile[],
3131
) => BeforeUploadFileType | Promise<void | BeforeUploadFileType> | void;
32-
customRequest?: (option: UploadRequestOption) => void;
32+
customRequest?: (option: UploadRequestOption) => void | { abort: () => void };
3333
withCredentials?: boolean;
3434
openFileDialogOnClick?: boolean;
3535
prefixCls?: string;
@@ -54,19 +54,21 @@ export type UploadRequestMethod = 'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'p
5454

5555
export type UploadRequestHeader = Record<string, string>;
5656

57+
export type UploadRequestFile = Exclude<BeforeUploadFileType, File | boolean> | RcFile;
58+
5759
export interface UploadRequestError extends Error {
5860
status?: number;
5961
method?: UploadRequestMethod;
6062
url?: string;
6163
}
6264

6365
export interface UploadRequestOption<T = any> {
64-
onProgress?: (event: UploadProgressEvent) => void;
66+
onProgress?: (event: UploadProgressEvent, file?: UploadRequestFile) => void;
6567
onError?: (event: UploadRequestError | ProgressEvent, body?: T) => void;
66-
onSuccess?: (body: T, xhr?: XMLHttpRequest) => void;
68+
onSuccess?: (body: T, fileOrXhr?: UploadRequestFile | XMLHttpRequest) => void;
6769
data?: Record<string, unknown>;
6870
filename?: string;
69-
file: Exclude<BeforeUploadFileType, File | boolean> | RcFile;
71+
file: UploadRequestFile;
7072
withCredentials?: boolean;
7173
action: string;
7274
headers?: UploadRequestHeader;

0 commit comments

Comments
 (0)