typia icon indicating copy to clipboard operation
typia copied to clipboard

instanceof checking

Open ion1 opened this issue 9 months ago • 0 comments

Hi,

I was hoping for this to check that the value is both defined and an instance of HTMLElement:

const isHTMLElement = typia.createIs<HTMLElement>();

However, the result is:

const isHTMLElement = (() => {
  return (input) => true;
})();

Similarly, I would like this to check that it is an instance of HTMLElement:

interface YouTubePlayerElement extends HTMLElement {
  getPlaybackRate: Function;
  setPlaybackRate: Function;
}

const isYouTubePlayerElement = typia.createIs<YouTubePlayerElement>();

The result is:

const isYouTubePlayerElement = (() => {
  const _io0 = (input) =>
    "object" === typeof input.getPlaybackRate &&
    null !== input.getPlaybackRate &&
    _io1(input.getPlaybackRate) &&
    "object" === typeof input.setPlaybackRate &&
    null !== input.setPlaybackRate &&
    _io1(input.setPlaybackRate);
  const _io1 = (input) =>
    true &&
    "number" === typeof input.length &&
    true &&
    "object" === typeof input.caller &&
    null !== input.caller &&
    _io1(input.caller) &&
    "string" === typeof input.name;
  return (input) => "object" === typeof input && null !== input && _io0(input);
})();

The use case is that YouTube patches the #movie_player element to have methods such as setPlaybackRate and I would like to be able to throw an Element or a Node at typia to get a YouTubePlayerElement which has been automatically checked to be a HTMLElement.

Thanks!

ion1 avatar May 29 '25 08:05 ion1