Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(server/tree): improve type safety
Elian Dorana7a94789e69c
diff --git a/apps/server/src/services/tree.ts b/apps/server/src/services/tree.tsindex 54013e8954..6211c5cd02 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<T>(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", reversereturn 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);});