fn

isEventTarget

v0.0.5

Type guard for a value that is itself an EventTarget(e.g. window, document, or an element) — i.e. it can be attached to directly rather than unwrapped from a ref/getter first.

Example

ts
if (isEventTarget(target))
  target.addEventListener('click', onClick);

Signature

ts
declare function isEventTarget(value: unknown): value is EventTarget;

Parameters

ParameterTypeDescription
valueunknownThe value to test

Returns

value is EventTargettrue when value is a non-null object exposing addEventListener