import 'typescript'; import 'typescript/lib/lib.dom'; export interface State { val: T; readonly oldVal: T; readonly rawVal: T; } // Defining readonly view of State for covariance. // Basically we want StateView to implement StateView export type StateView = Readonly>; export type Val = State | T; export type Primitive = string | number | boolean | bigint; export type PropValue = Primitive | ((e: any) => void) | null; export type PropValueOrDerived = | PropValue | StateView | (() => PropValue); export type Props = Record & { class?: PropValueOrDerived; }; export type PropsWithKnownKeys = Partial<{ [K in keyof ElementType]: PropValueOrDerived; }>; export type ValidChildDomValue = Primitive | Node | null | undefined; export type BindingFunc = | ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element); export type ChildDom = | ValidChildDomValue | StateView | BindingFunc | readonly ChildDom[]; export type TagFunc = ( first?: (Props & PropsWithKnownKeys) | ChildDom, ...rest: readonly ChildDom[] ) => Result; type Tags = Readonly>> & { [K in keyof HTMLElementTagNameMap]: TagFunc; }; declare function state(): State; declare function state(initVal: T): State; export interface Van { readonly state: typeof state; readonly derive: (f: () => T) => State; readonly add: (dom: Element, ...children: readonly ChildDom[]) => Element; readonly tags: Tags & ((namespaceURI: string) => Readonly>>); readonly hydrate: ( dom: T, f: (dom: T) => T | null | undefined, ) => T; } declare global { const van: Van; }