From 608a9ad347320365b4838e27413b4ca04afe9785 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Thu, 28 Jan 2021 21:07:17 +0100 Subject: [PATCH] use type guard --- front/src/WebRtc/HtmlUtils.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/front/src/WebRtc/HtmlUtils.ts b/front/src/WebRtc/HtmlUtils.ts index 48c1e092..9b4d9bb8 100644 --- a/front/src/WebRtc/HtmlUtils.ts +++ b/front/src/WebRtc/HtmlUtils.ts @@ -8,12 +8,11 @@ export class HtmlUtils { } public static querySelectorOrFail(selector: string): T { - const elem = document.querySelector(selector); - if (elem === null) { - throw new Error("Cannot find HTML element with selector '"+selector+"'"); + const elem = document.querySelector(selector); + 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 selector '"+selector+"'"); } public static removeElementByIdOrFail(id: string): T {