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(client/ts): fix errors related to autocomplete
Elian Doranffd609e0c5c1
diff --git a/src/public/app/services/attribute_autocomplete.ts b/src/public/app/services/attribute_autocomplete.tsindex 04c601f461..0411299742 100644--- a/src/public/app/services/attribute_autocomplete.ts+++ b/src/public/app/services/attribute_autocomplete.ts@@ -1,11 +1,19 @@+import { AttributeType } from "../entities/fattribute.js";import server from "./server.js";+interface InitOptions {+ $el: JQuery<HTMLElement>;+ attributeType: AttributeType | (() => AttributeType);+ open: boolean;+ nameCallback: () => string;+}+/*** @param $el - element on which to init autocomplete* @param attributeType - "relation" or "label" or callback providing one of those values as a type of autocompleted attributes* @param open - should the autocomplete be opened after init?*/-function initAttributeNameAutocomplete({ $el, attributeType, open }) {+function initAttributeNameAutocomplete({ $el, attributeType, open }: InitOptions) {if (!$el.hasClass("aa-input")) {$el.autocomplete({appendTo: document.querySelector('body'),@@ -39,7 +47,7 @@ function initAttributeNameAutocomplete({ $el, attributeType, open }) {}}-async function initLabelValueAutocomplete({ $el, open, nameCallback }) {+async function initLabelValueAutocomplete({ $el, open, nameCallback }: InitOptions) {if ($el.hasClass("aa-input")) {// we reinit every time because autocomplete seems to have a bug where it retains state from last// open even though the value was resetdiff --git a/src/public/app/services/options.ts b/src/public/app/services/options.tsindex 23cddcfd91..138c0402a9 100644--- a/src/public/app/services/options.ts+++ b/src/public/app/services/options.ts@@ -1,7 +1,7 @@import server from "./server.js";-type OptionValue = string;+type OptionValue = number | string;class Options {initializedPromise: Promise<void>;diff --git a/src/public/app/types.d.ts b/src/public/app/types.d.tsindex 705a16b3a3..4fb103b796 100644--- a/src/public/app/types.d.ts+++ b/src/public/app/types.d.ts@@ -47,8 +47,24 @@ declare global {glob?: CustomGlobals;}+ interface AutoCompleteConfig {+ appendTo?: HTMLElement | null;+ hint?: boolean;+ openOnFocus?: boolean;+ minLength?: number;+ tabAutocomplete?: boolean+ }++ type AutoCompleteCallback = (values: AutoCompleteCallbackArgs[]) => void;++ interface AutoCompleteArg {+ displayKey: "name" | "value";+ cache: boolean;+ source: (term: string, cb: AutoCompleteCallback) => void+ };+interface JQuery {- // autocomplete: (action: "close") => void;+ autocomplete: (action: "close" | "open" | "destroy" | AutoCompleteConfig, args?: AutoCompleteArg[]) => void;}var logError: (message: string) => void;