typia icon indicating copy to clipboard operation
typia copied to clipboard

Checking of functions in interface definitions

Open ion1 opened this issue 9 months ago • 0 comments

Hi,

It would be nice if these functions were checked at least to some extent.

interface YouTubePlayerElement extends HTMLElement {
  getPlaybackRate(): number;
  setPlaybackRate(rate: number): void;
}

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

Right now, their existence is not being checked to any extent:

const isYouTubePlayerElement = (() => {
  const _io0 = (input) => true;
  return (input) =>
    "object" === typeof input &&
    null !== input &&
    false === Array.isArray(input) &&
    _io0(input);
})();

I suppose there are at least three levels of checking one could think of:

  • Check that the object has the keys getPlaybackRate and setPlaybackRate and the values are defined.
  • Check that they are Functions, similarly to how this is checked:
    interface YouTubePlayerElement extends HTMLElement {
      getPlaybackRate: Function;
      setPlaybackRate: Function;
    }
    
  • Check that they are Functions, and also construct a typia.functional wrapper for both. I'm fine with having to use something other than is to achieve that. Now that I think of it, I'm not sure if that is compatible with the result extending HTMLElement though. Perhaps the result could be a Proxy<YouTubePlayerElement>?

The use case is that YouTube patches the #movie_player element with methods such as getPlaybackRate and setBackRate, and I would like to use Typia to check that the element has the methods I expect.

Thanks!

ion1 avatar May 29 '25 08:05 ion1