export interface NameDetails { username: string isMod: boolean } export function innermostElement( elem: T ): U { if (elem.children.length === 0) { // U is the type of the innermost element // since we're at the innermost element, we know T = U // so we can cast elem (T) to U return elem as any as U } let child = elem.children[0] return innermostElement(child) } export function elementTreeFind( elem: T, fn: (elem: Element) => boolean ): U | null { if (fn(elem)) { // U is the type of the element that satisfies fn() // since we're at the element that satisfies fn(), we know T = U // so we can cast elem (T) to U return elem as any as U } if (!elem.parentElement) { return null } return elementTreeFind(elem.parentElement, fn) }