diff --git a/front/src/WebRtc/HtmlUtils.ts b/front/src/WebRtc/HtmlUtils.ts index 81f069b3..168fba1e 100644 --- a/front/src/WebRtc/HtmlUtils.ts +++ b/front/src/WebRtc/HtmlUtils.ts @@ -1,21 +1,19 @@ export class HtmlUtils { public static getElementByIdOrFail(id: string): T { const elem = document.getElementById(id); - if (elem === null) { - throw new Error("Cannot find HTML element with id '"+id+"'"); + if (HtmlUtils.isHtmlElement(elem)) { + return elem; } - // FIXME: does not check the type of the returned type - return elem as T; + throw new Error("Cannot find HTML element with id '"+id+"'"); } public static removeElementByIdOrFail(id: string): T { const elem = document.getElementById(id); - if (elem === null) { - throw new Error("Cannot find HTML element with id '"+id+"'"); + if (HtmlUtils.isHtmlElement(elem)) { + elem.remove(); + return elem; } - // FIXME: does not check the type of the returned type - elem.remove(); - return elem as T; + throw new Error("Cannot find HTML element with id '"+id+"'"); } public static urlify(text: string): string { @@ -24,4 +22,8 @@ export class HtmlUtils { return '' + url + ''; }) } + + private static isHtmlElement(elem: HTMLElement | null): elem is T { + return elem !== null; + } }