export function querySelectorOrThrow()

in src/lib/dom.ts [19:34]


export function querySelectorOrThrow<T extends Element>(
  parent: Document | Element,
  type: Constructor<T>,
  s: string
): T {
  const elem = parent.querySelector<T>(s);
  if (!elem) {
    throw new Error(`querySelector(${s}) returned null`);
  }
  if (!(elem instanceof type)) {
    throw new Error(
      `type didn't match: expected ${typeof type}, actual ${typeof elem}`
    );
  }
  return elem;
}