From 2b29093c5298154c11cbb6506f8dc54b45f859b5 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Tue, 7 Feb 2023 14:09:45 +0800 Subject: [PATCH] type: update upload fileList type (#40585) --- components/upload/utils.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/upload/utils.tsx b/components/upload/utils.tsx index 6e67359156..61b9f930fe 100644 --- a/components/upload/utils.tsx +++ b/components/upload/utils.tsx @@ -15,9 +15,9 @@ export function file2Obj(file: RcFile): InternalUploadFile { } /** Upload fileList. Replace file if exist or just push into it. */ -export function updateFileList(file: UploadFile, fileList: UploadFile[]) { +export function updateFileList(file: UploadFile, fileList: (UploadFile | Readonly)[]) { const nextFileList = [...fileList]; - const fileIndex = nextFileList.findIndex(({ uid }: UploadFile) => uid === file.uid); + const fileIndex = nextFileList.findIndex(({ uid }) => uid === file.uid); if (fileIndex === -1) { nextFileList.push(file); } else { @@ -26,12 +26,12 @@ export function updateFileList(file: UploadFile, fileList: UploadFile[ return nextFileList; } -export function getFileItem(file: RcFile, fileList: UploadFile[]) { +export function getFileItem(file: RcFile, fileList: (UploadFile | Readonly)[]) { const matchKey = file.uid !== undefined ? 'uid' : 'name'; return fileList.filter((item) => item[matchKey] === file[matchKey])[0]; } -export function removeFileItem(file: UploadFile, fileList: UploadFile[]) { +export function removeFileItem(file: UploadFile, fileList: (UploadFile | Readonly)[]) { const matchKey = file.uid !== undefined ? 'uid' : 'name'; const removed = fileList.filter((item) => item[matchKey] !== file[matchKey]); if (removed.length === fileList.length) { @@ -74,6 +74,7 @@ export const isImageUrl = (file: UploadFile): boolean => { }; const MEASURE_SIZE = 200; + export function previewImage(file: File | Blob): Promise { return new Promise((resolve) => { if (!file.type || !isImageFileType(file.type)) {