react-youtube
react-youtube copied to clipboard
YouTubePlayer method types say they are async, but they aren't
Hi, I think I've found a bug in the Typescript typing. The callback functions such as onReady take a YouTubeEvent argument, that contains a YouTubePlayer object:
function onReady(event: YouTubeEvent) {
const player = event.target;
const time = player.getCurrentTime();
console.log('time:', time);
}
According to the types, time should be a Promise<number>, so you should have to await it. But actually, it is just a plain number. To get my code to typecheck and run I have to actually do:
const time = player.getCurrentTime() as any as number
I'm not really sure what the correct behavior would be. youtube-player wraps the player object and makes every method return promises, which is useful because it allows you to await the method calls until they are ready. But changing event.target to return the wrapped player (and match the types) would probably break some existing code.
I'm using react-youtube version 10.1.0 and youtube-player 5.5.2.