From da16bb1a5d841b45422e40782085a48a75492229 Mon Sep 17 00:00:00 2001 From: idylls Date: Fri, 17 Feb 2023 12:18:58 -0500 Subject: [PATCH] Update exports, add `Renderable` type `Renderable` type is useful for 3rd-party code which wants to accept any `swel`-renderable type --- mod.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mod.ts b/mod.ts index 1ca76cc..fef76d2 100644 --- a/mod.ts +++ b/mod.ts @@ -4,15 +4,15 @@ type BasicProperties = { [K in keyof T as T[K] extends string | number | boolean ? K : never]: T[K]; }; -type Child = Node | string | null; -type SwelOpts = Partial< +export type Child = Node | string | null; +export type SwelOpts = Partial< BasicProperties > & { on: Partial<{ [Ev in keyof HTMLElementEventMap]: ( this: HTMLElement, ev: HTMLElementEventMap[Ev], - ) => any; + ) => void; }>; children: (Node | string)[] | null; attributes: Record; @@ -20,6 +20,8 @@ type SwelOpts = Partial< style: Record | null; }; +export type Renderable = Child | Child[]; + interface Swel { ( tag: T, @@ -47,12 +49,23 @@ interface Swel { opts?: Partial, "children">>, child?: Child, ): HTMLElementTagNameMap[T]; + + ( + tag: T, + opts?: Partial, "children">>, + renderable?: Renderable, + ): HTMLElementTagNameMap[T]; + + ( + tag: T, + renderable?: Renderable, + ): HTMLElementTagNameMap[T]; } export const swel: Swel = ( tag: T, - opts?: Partial> | Child | Child[], - children?: Child | Child[], + opts?: Partial> | Renderable, + children?: Renderable, ): HTMLElementTagNameMap[T] => { let o: Partial> | null = null; if (children) {