declare global { namespace VanX { type StateOf = { readonly [K in keyof T]: Van.State } type ValueType = T extends (infer V)[] ? V : T[keyof T] type KeyType = T extends unknown[] ? number : string type ReplacementFunc = T extends (infer V)[] ? (items: V[]) => readonly V[] : (items: [string, T[keyof T]][]) => readonly [string, T[keyof T]][] } namespace Van { interface State { val: T readonly oldVal: T readonly rawVal: T } // Defining readonly view of State for covariance. // Basically we want StateView to implement StateView type StateView = Readonly> type Val = State | T type Primitive = string | number | boolean | bigint // deno-lint-ignore no-explicit-any type PropValue = Primitive | ((e: any) => void) | null type PropValueOrDerived = PropValue | StateView | (() => PropValue) type Props = Record & { class?: PropValueOrDerived; is?: string } type PropsWithKnownKeys = Partial<{[K in keyof ElementType]: PropValueOrDerived}> type ValidChildDomValue = Primitive | Node | null | undefined type BindingFunc = ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element) type ChildDom = ValidChildDomValue | StateView | BindingFunc | readonly ChildDom[] type TagFunc = (first?: Props & PropsWithKnownKeys | ChildDom, ...rest: readonly ChildDom[]) => Result type Tags = Readonly>> & { [K in keyof HTMLElementTagNameMap]: TagFunc } } const van:MembersVan; const vanX:MembersVanX; } type MembersVan = { readonly state: (initVal: T)=> Van.State readonly derive: (f: () => T) => Van.State readonly add: (dom: Element, ...children: readonly Van.ChildDom[]) => Element readonly tags: Van.Tags & ((namespaceURI: string) => Readonly>>) readonly hydrate: (dom: T, f: (dom: T) => T | null | undefined) => T } type MembersVanX = { readonly calc: (f: () => R) => R readonly reactive: (obj: T) => T readonly noreactive: (obj: T) => T readonly stateFields: (obj: T) => VanX.StateOf readonly raw: (obj: T) => T readonly list: (container: (() => ElementType) | ElementType, items: T,itemFunc: (v: Van.State>, deleter: () => void, k: VanX.KeyType) => Node) => ElementType readonly replace: (obj: T, replacement: VanX.ReplacementFunc | T) => T readonly compact: (obj: T) => T } export const Van: MembersVan; export const VanX: MembersVanX;