Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YouTubePlayer method types say they are async, but they aren't #407

Open
jdmansour opened this issue Nov 20, 2023 · 0 comments
Open

YouTubePlayer method types say they are async, but they aren't #407

jdmansour opened this issue Nov 20, 2023 · 0 comments

Comments

@jdmansour
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant