Skip to content

Commit 0728c90

Browse files
committed
chore: update upload typo
1 parent 9a100b0 commit 0728c90

File tree

1 file changed

+53
-17
lines changed

1 file changed

+53
-17
lines changed

types/upload.d.ts

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
import { AntdComponent } from './component';
66

7+
export interface HttpRequestHeader {
8+
[key: string]: string;
9+
}
10+
711
export interface VcFile extends File {
812
uid: string;
913
readonly lastModifiedDate: Date;
@@ -30,7 +34,25 @@ export interface UploadFile<T = any> {
3034
preview?: string;
3135
}
3236

33-
export interface ShowUploadList {
37+
export interface UploadChangeParam<T extends object = UploadFile> {
38+
file: T;
39+
fileList: UploadFile[];
40+
event?: { percent: number };
41+
}
42+
43+
export interface VcCustomRequestOptions {
44+
onProgress: (event: { percent: number }, file: File) => void;
45+
onError: (error: Error) => void;
46+
onSuccess: (response: object, file: File) => void;
47+
data: object;
48+
filename: string;
49+
file: File;
50+
withCredentials: boolean;
51+
action: string;
52+
headers: object;
53+
}
54+
55+
export interface ShowUploadListInterface {
3456
showRemoveIcon?: boolean;
3557
showPreviewIcon?: boolean;
3658
showDownloadIcon?: boolean;
@@ -66,7 +88,7 @@ export declare class Upload extends AntdComponent {
6688
* Uploading URL
6789
* @type string | Function
6890
*/
69-
action?: string | Function;
91+
action?: string | ((file: VcFile) => string) | ((file: VcFile) => PromiseLike<string>);
7092

7193
/**
7294
* support upload whole directory
@@ -81,19 +103,41 @@ export declare class Upload extends AntdComponent {
81103
* Warning:this function is not supported in IE9.
82104
* @type Function
83105
*/
84-
beforeUpload?: (file: any, fileList: UploadFile[]) => boolean | Promise<boolean>;
106+
beforeUpload?: (file: VcFile, fileList: VcFile[]) => boolean | Promise<boolean>;
107+
108+
/**
109+
* A callback function, can be executed when uploading state is changing.
110+
*/
111+
onChange?: (info: UploadChangeParam) => void;
112+
113+
/**
114+
* A callback function, will be executed when file link or preview icon is clicked.
115+
*/
116+
onPreview?: (file: UploadFile) => void;
117+
118+
/**
119+
* Click the method to download the file, pass the method to perform the method logic, do not pass the default jump to the new TAB.
120+
*/
121+
onDownload?: (file: UploadFile) => void;
122+
123+
/**
124+
* A callback function, will be executed when removing file button is clicked,
125+
* remove event will be prevented when return value is false or a Promise which resolve(false) or reject.
126+
* @type Function
127+
*/
128+
onRemove?: (file: UploadFile) => boolean | Promise<boolean>;
85129

86130
/**
87131
* override for the default xhr behavior allowing for additional customization and ability to implement your own XMLHttpRequest
88132
* @type Function
89133
*/
90-
customRequest?: Function;
134+
customRequest?: (options: VcCustomRequestOptions) => void;
91135

92136
/**
93137
* Uploading params or function which can return uploading params.
94138
* @type object | Function
95139
*/
96-
data?: object | Function;
140+
data?: object | ((file: UploadFile) => object);
97141
/**
98142
* http method of upload request
99143
*/
@@ -122,7 +166,7 @@ export declare class Upload extends AntdComponent {
122166
* Set request headers, valid above IE10.
123167
* @type object
124168
*/
125-
headers?: object;
169+
headers?: HttpRequestHeader;
126170

127171
/**
128172
* Built-in stylesheets, support for three types: text, picture or picture-card
@@ -149,9 +193,9 @@ export declare class Upload extends AntdComponent {
149193
/**
150194
* Whether to show default upload list, could be an object to specify showPreviewIcon and showRemoveIcon individually
151195
* @default true
152-
* @type boolean | ShowUploadList
196+
* @type boolean | ShowUploadListInterface
153197
*/
154-
showUploadList?: boolean | ShowUploadList;
198+
showUploadList?: boolean | ShowUploadListInterface;
155199

156200
/**
157201
* Need to be turned on while the server side is rendering.
@@ -174,13 +218,6 @@ export declare class Upload extends AntdComponent {
174218
*/
175219
openFileDialogOnClick?: boolean;
176220

177-
/**
178-
* A callback function, will be executed when removing file button is clicked,
179-
* remove event will be prevented when return value is false or a Promise which resolve(false) or reject.
180-
* @type Function
181-
*/
182-
remove?: (file: any) => boolean | Promise<boolean>;
183-
184221
locale?: UploadLocale;
185222
id?: string;
186223
/**
@@ -191,6 +228,5 @@ export declare class Upload extends AntdComponent {
191228
* Customize transform file before request (1.5.0)
192229
*/
193230
transformFile?: TransformFileHandler;
194-
}
195-
231+
};
196232
}

0 commit comments

Comments
 (0)