From 5a1d8469d60c800500247c42f0d032ade149ebaf Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Wed, 14 May 2025 10:19:10 +1000 Subject: [PATCH] Add ComponentOptions type definition and update index.ts to use it --- src/index.ts | 9 +-------- src/types/ComponentOptions.d.ts | 8 ++++++++ tsconfig.json | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 src/types/ComponentOptions.d.ts diff --git a/src/index.ts b/src/index.ts index 656ee09..ac5ebd8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,4 @@ -export default (options: { - tag: string - template: string - style?: string - onMount?: () => void - onUnmount?: () => void - onAttributeChanged?: (attrName: string, oldValue: string, newValue: string) => void -}) => { +export default (options: ComponentOptions) => { const { tag, template, style, onMount, onUnmount, onAttributeChanged } = options class CustomElement extends HTMLElement { diff --git a/src/types/ComponentOptions.d.ts b/src/types/ComponentOptions.d.ts new file mode 100644 index 0000000..0eaa9ad --- /dev/null +++ b/src/types/ComponentOptions.d.ts @@ -0,0 +1,8 @@ +interface ComponentOptions { + tag: string + template: string + style?: string + onMount?: () => void + onUnmount?: () => void + onAttributeChanged?: (attrName: string, oldValue: string, newValue: string) => void +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index c2ab235..bd46907 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,7 +32,7 @@ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + "typeRoots": ["./src/types"], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */