From 41d7728d182f1bb06ecf2b74fdb07426282aa779 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Wed, 5 Mar 2025 16:24:06 +0100 Subject: [PATCH] :bug: fixes completitions for el with components --- examples/components/todosComponent.js | 4 ++-- index.d.ts | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/components/todosComponent.js b/examples/components/todosComponent.js index da9c34d..9f552ba 100644 --- a/examples/components/todosComponent.js +++ b/examples/components/todosComponent.js @@ -45,7 +45,7 @@ export function todosComponent({ todos= [ "Task A" ] }= {}){ : el("ul").append( ...Array.from(ts).map(([ value, textContent ])=> memo(value, ()=> el(todoComponent, { textContent, value, className }, onremove))) - ) + ), ), el("p", "Click to the text to edit it.") ), @@ -54,7 +54,7 @@ export function todosComponent({ todos= [ "Task A" ] }= {}){ el("label", "New todo: ").append( el("input", { name, type: "text", required: true }), ), - el("button", "+") + el("button", "+"), ), el("div").append( el("h3", "Output (JSON):"), diff --git a/index.d.ts b/index.d.ts index 6f6749f..f527b33 100644 --- a/index.d.ts +++ b/index.d.ts @@ -72,6 +72,16 @@ export function assignAttribute[ATT] type ExtendedHTMLElementTagNameMap= HTMLElementTagNameMap & CustomElementTagNameMap; +export function el< + A extends ddeComponentAttributes, + EL extends SupportedElement | ddeDocumentFragment +>( + component: (attr: A)=> EL, + attrs?: A extends { textContent: any } ? ( NoInfer | ddeStringable ) : NoInfer, + ...addons: ddeElementAddon[] +): EL extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap] + ? EL + : ( EL extends ddeDocumentFragment ? EL : ddeHTMLElement ) export function el< TAG extends keyof ExtendedHTMLElementTagNameMap, >( @@ -89,16 +99,6 @@ export function el( attrs?: ElementAttributes | ddeStringable, ...addons: ddeElementAddon[] ): ddeHTMLElement - -export function el< - C extends (attr: ddeComponentAttributes)=> SupportedElement | ddeDocumentFragment ->( - component: C, - attrs?: Parameters[0] | ddeStringable, - ...addons: ddeElementAddon>[] -): ReturnType extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap] - ? ReturnType - : ( ReturnType extends ddeDocumentFragment ? ReturnType : ddeHTMLElement ) export { el as createElement } export function elNS(