Skip to content
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
1 task done
whtsky opened this issue Mar 23, 2018 · 7 comments · Fixed by #10059
Closed
1 task done

Uploader component does not provide correct type info #9775

whtsky opened this issue Mar 23, 2018 · 7 comments · Fixed by #10059

Comments

@whtsky
Copy link
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
Copy link
Member

yesmeck commented Mar 23, 2018

The file is the "originFileObj"

@yesmeck yesmeck closed this as completed Mar 23, 2018
@whtsky
Copy link
Contributor Author

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
Copy link
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
Copy link
Contributor Author

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

@ghost
Copy link

ghost commented Mar 25, 2018

Also in "fileList" parameter the type is wrong.

@afc163 afc163 reopened this Mar 26, 2018
@bora89
Copy link

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?

@whtsky
Copy link
Contributor Author

whtsky commented Apr 15, 2018

any updates on this?

whtsky added a commit to whtsky/ant-design that referenced this issue Apr 16, 2018
afc163 pushed a commit that referenced this issue Apr 19, 2018
* 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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants