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

fix(image-uploader): upload props ts type #6821

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/image-uploader/image-uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
file: File,
files: File[]
) => Promise<File | null> | File | null
upload: (file: File) => Promise<ImageUploadItem>
upload?: (file: File) => Promise<ImageUploadItem>
onDelete?: (item: ImageUploadItem) => boolean | Promise<boolean> | void
preview?: boolean
showFailed?: boolean
Expand Down Expand Up @@ -199,7 +199,7 @@
await Promise.all(
newTasks.map(async (currentTask, index) => {
try {
const result = await props.upload(currentTask.file)
const result = await props.upload!(currentTask.file)

Check warning on line 202 in src/components/image-uploader/image-uploader.tsx

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样会有问题,upload 不传会报错。

Copy link
Author

@huangmingfu huangmingfu Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,其他情况会,我是看他说的 disableUpload 的情况,onChange 就不会触发。
多加一个这个呢?

if (!props.upload && !props.disableUpload) { 
   console.error('提示upload必传')
   return
}

newVal[index] = result
setTasks(prev => {
return prev.map(task => {
Expand Down
Loading