Skip to content

Commit

Permalink
refactor: remove unsed ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jul 26, 2022
1 parent 46a466f commit 22d782a
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/util/extractFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ function normalizeItems(items: DataTransferItem[]) {
let entry: FileSystemEntry | File[]
// Edge throws
try {
// @ts-expect-error
entry = item.webkitGetAsEntry()
} catch (err) {
return [item.getAsFile()]
}
if (!entry) {
return []
}
// @ts-expect-error
return entry.isDirectory ? walk(entry) : [item.getAsFile()]
}

Expand All @@ -40,7 +38,6 @@ function normalizeItems(items: DataTransferItem[]) {
}

// others
// @ts-expect-error
return new Promise((resolve) => item.getAsString(resolve)).then((str?: string) =>
str ? [new File([str], 'unknown.txt', {type: item.type})] : []
)
Expand All @@ -55,20 +52,16 @@ function isDirectory(entry: FileSystemEntry): entry is FileSystemDirectoryEntry
return entry.isDirectory
}

// @ts-expect-error
function walk(entry: FileSystemEntry) {
if (isFile(entry)) {
return new Promise((resolve) => entry.file(resolve)).then((file) => [file])
}

if (isDirectory(entry)) {
const dir = entry.createReader()
return (
new Promise((resolve) => dir.readEntries(resolve))
// @ts-expect-error
.then((entries: FileSystemEntry[]) => entries.filter((entr) => !entr.name.startsWith('.')))
.then((entries) => Promise.all(entries.map(walk)).then((arr) => arr.flat()))
)
return new Promise((resolve) => dir.readEntries(resolve))
.then((entries: FileSystemEntry[]) => entries.filter((entr) => !entr.name.startsWith('.')))
.then((entries) => Promise.all(entries.map(walk)).then((arr) => arr.flat()))
}
return Promise.resolve([])
}

0 comments on commit 22d782a

Please sign in to comment.