type: update upload fileList type (#40585)

This commit is contained in:
lijianan 2023-02-07 14:09:45 +08:00 committed by GitHub
parent e5c4bbc693
commit 2b29093c52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<any>, fileList: UploadFile<any>[]) {
export function updateFileList(file: UploadFile, fileList: (UploadFile | Readonly<UploadFile>)[]) {
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<any>, fileList: UploadFile<any>[
return nextFileList;
}
export function getFileItem(file: RcFile, fileList: UploadFile[]) {
export function getFileItem(file: RcFile, fileList: (UploadFile | Readonly<UploadFile>)[]) {
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<UploadFile>)[]) {
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<string> {
return new Promise((resolve) => {
if (!file.type || !isImageFileType(file.type)) {