typia
typia copied to clipboard
Checking of functions in interface definitions
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
getPlaybackRateandsetPlaybackRateand 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.functionalwrapper for both. I'm fine with having to use something other thanisto achieve that. Now that I think of it, I'm not sure if that is compatible with the result extendingHTMLElementthough. Perhaps the result could be aProxy<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!