Use instanceof instead of duck typing for TAbstractFile

This commit is contained in:
Isaac Lyman 2022-03-09 13:50:58 -07:00
parent 075225298f
commit 0da5b3ebe7
1 changed files with 6 additions and 5 deletions

View File

@ -51,15 +51,16 @@ export class FileHelper {
abstractFile: TAbstractFile,
counts: CountsByFile
): Promise<void> {
if ((abstractFile as TFolder).children) {
if (abstractFile instanceof TFolder) {
Object.assign(counts, this.getAllFileCounts());
return;
}
const file = abstractFile as TFile;
const contents = await this.vault.cachedRead(file);
const wordCount = this.countWords(contents);
this.setCounts(counts, file.path, wordCount);
if (abstractFile instanceof TFile) {
const contents = await this.vault.cachedRead(abstractFile);
const wordCount = this.countWords(contents);
this.setCounts(counts, abstractFile.path, wordCount);
}
}
private countWords(content: string): number {