use type guard
This commit is contained in:
parent
b52c546a8c
commit
608a9ad347
@ -8,12 +8,11 @@ export class HtmlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static querySelectorOrFail<T extends HTMLElement>(selector: string): T {
|
public static querySelectorOrFail<T extends HTMLElement>(selector: string): T {
|
||||||
const elem = document.querySelector(selector);
|
const elem = document.querySelector<T>(selector);
|
||||||
if (elem === null) {
|
if (HtmlUtils.isHtmlElement<T>(elem)) {
|
||||||
throw new Error("Cannot find HTML element with selector '"+selector+"'");
|
return elem;
|
||||||
}
|
}
|
||||||
// FIXME: does not check the type of the returned type
|
throw new Error("Cannot find HTML element with selector '"+selector+"'");
|
||||||
return elem as T;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static removeElementByIdOrFail<T extends HTMLElement>(id: string): T {
|
public static removeElementByIdOrFail<T extends HTMLElement>(id: string): T {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user