From 0da5b3ebe7210eabb1616d571d919ecb3dce703a Mon Sep 17 00:00:00 2001 From: Isaac Lyman Date: Wed, 9 Mar 2022 13:50:58 -0700 Subject: [PATCH] Use instanceof instead of duck typing for TAbstractFile --- logic/file.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/logic/file.ts b/logic/file.ts index edbd3a9..f4352ba 100644 --- a/logic/file.ts +++ b/logic/file.ts @@ -51,15 +51,16 @@ export class FileHelper { abstractFile: TAbstractFile, counts: CountsByFile ): Promise { - 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 {