New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploader component does not provide correct type info #9775

Closed
whtsky opened this Issue Mar 23, 2018 · 7 comments

Comments

Projects
None yet
8 participants
@whtsky
Contributor

whtsky commented Mar 23, 2018

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

3.3.1

Environment

N/A

Reproduction link

Edit on CodeSandbox

Steps to reproduce

click upload, select a file

What is expected?

console output has originFileObj, is UploadFile!!!

What is actually happening?

console output nop, not a upload file


in Upload component's typing, it claims beforeUpload callback will receive a UploadFile typed object, but in fact we receive a File object.
Which causes a lot of trouble when using in TypeScript, for now we write a lot of as any as File type cast just to get a correct type.

@yesmeck

This comment has been minimized.

Member

yesmeck commented Mar 23, 2018

The file is the "originFileObj"

@yesmeck yesmeck closed this Mar 23, 2018

@whtsky

This comment has been minimized.

Contributor

whtsky commented Mar 23, 2018

Yes, but the typing is wrong. Wrong typing causes a lot of trouble for TypeScript users.
https://github.com/ant-design/ant-design/blob/master/components/upload/interface.tsx#L56

@pizn

This comment has been minimized.

Contributor

pizn commented Mar 25, 2018

Which causes a lot of trouble when using in TypeScript, for now we write a lot of as any as File type cast just to get a correct type.

This is not a reason to modify the file type. beforeUpload should be return the real File for user to control, such like file verification.

eg: On beforeupload to get image size with use fileReader / window.URL. createObjectURL(file).

@whtsky

This comment has been minimized.

Contributor

whtsky commented Mar 25, 2018

beforeUpload should be return the real File for user to control, such like file verification.

total agree, I think fixing the typing is better than do break change

@danielg2002

This comment has been minimized.

Contributor

danielg2002 commented Mar 25, 2018

Also in "fileList" parameter the type is wrong.

@afc163 afc163 reopened this Mar 26, 2018

@bora89

This comment has been minimized.

bora89 commented Mar 26, 2018

Yes guys, type of FileList now is an Array. Can not use it in that way. I would like to get real FileList type read-only object as native file input returns (with multiple attr). When to expect it to appear?

zheeeng added a commit to zheeeng/ant-design that referenced this issue Apr 12, 2018

@whtsky

This comment has been minimized.

Contributor

whtsky commented Apr 15, 2018

any updates on this?

whtsky added a commit to whtsky/ant-design that referenced this issue Apr 15, 2018

@whtsky whtsky referenced this issue Apr 15, 2018

Merged

fix typing for `Upload.beforeUpload` #10059

10 of 10 tasks complete

whtsky added a commit to whtsky/ant-design that referenced this issue Apr 15, 2018

whtsky added a commit to whtsky/ant-design that referenced this issue Apr 16, 2018

afc163 added a commit that referenced this issue Apr 19, 2018

fix typing for `Upload.beforeUpload` (#10059)
* fix typing for `Upload.beforeUpload`
fix #9775

* add RcFile interface, fix tests

* fix typing of `Upload.onStart`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment