// I would've LOVED to use generics for this but unfortunately that's not possible. // Type safety, but at what cost... >~< thanks TypeScript export function findDialogOrFail(on: Element, selector: string): HTMLDialogElement { const element = on.querySelector(selector); if (!(element instanceof HTMLDialogElement)) throw new Error(`${selector} isn't a dialog`); return element; } export function findFormOrFail(on: Element, selector: string): HTMLFormElement { const element = on.querySelector(selector); if (!(element instanceof HTMLFormElement)) throw new Error(`${selector} isn't a form`); return element; } export function findInputOrFail(on: Element, selector: string): HTMLInputElement { const element = on.querySelector(selector); if (!(element instanceof HTMLInputElement)) throw new Error(`${selector} isn't an input`); return element; } export function findButtonOrFail(on: Element, selector: string): HTMLButtonElement { const element = on.querySelector(selector); if (!(element instanceof HTMLButtonElement)) throw new Error(`${selector} isn't a button`); return element; } export function findSelectOrFail(on: Element, selector: string): HTMLSelectElement { const element = on.querySelector(selector); if (!(element instanceof HTMLSelectElement)) throw new Error(`${selector} isn't a select`); return element; } export function findImageOrFail(on: Element, selector: string): HTMLImageElement { const element = on.querySelector(selector); if (!(element instanceof HTMLImageElement)) throw new Error(`${selector} isn't an image`); return element; }