isElementType.Function.isElementType - GyldendalDigital/kobber GitHub Wiki

@gyldendal/kobber-components / isElementType / isElementType

isElementType<T>(value, ElementClass): value is T

Defined in: packages/kobber-components/src/utils/isElementType.ts:25

Type guard for narrowing an element's type.

Type Parameters

T extends Element

Parameters

value

undefined | null | Element

ElementClass

() => Element

prototype

Element

Returns

value is T

Examples

Example using a native element

if(isElementType<HTMLAnchorElement>(myElement, HTMLAnchorElement)) {
  console.log(myElement.href);
}

Example using a web component

if(isElementType<MyWebComponent>(myElement, MyWebComponent)) {
  console.log(myElement.customProperty);
}
⚠️ **GitHub.com Fallback** ⚠️