diff --git a/apps/server/src/services/tree.ts b/apps/server/src/services/tree.ts index 54013e895..6211c5cd0 100644 --- a/apps/server/src/services/tree.ts +++ b/apps/server/src/services/tree.ts @@ -92,7 +92,10 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse } const notes = note.getChildNotes(); - const normalize = (obj: any) => (obj && typeof obj === "string" ? obj.toLowerCase() : obj); + + function normalize(obj: T | string) { + return obj && typeof obj === "string" ? obj.toLowerCase() : obj; + } notes.sort((a, b) => { if (foldersFirst) { @@ -106,7 +109,7 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse } function fetchValue(note: BNote, key: string) { - let rawValue; + let rawValue: string | null; if (key === "title") { const branch = note.getParentBranches().find((branch) => branch.parentNoteId === parentNoteId); @@ -151,15 +154,15 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1); } - const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title"); - const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title"); + const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title") as string; + const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title") as string; if (customAEl !== customBEl) { return compare(customAEl, customBEl); } - const titleAEl = fetchValue(a, "title"); - const titleBEl = fetchValue(b, "title"); + const titleAEl = fetchValue(a, "title") as string; + const titleBEl = fetchValue(b, "title") as string; return compare(titleAEl, titleBEl); });