cookpete / react-player

A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
https://cookpete.github.io/react-player
MIT License
8.89k stars 1.12k forks source link

BaseReactPlayer types are not correct #1739

Open bnbs opened 3 months ago

bnbs commented 3 months ago

I'm implementing a custom player in TypeScript and for this I have a class that extends BaseReactPlayer<ReactPlayerProps>. I initialize duration, currentTime and secondsLoaded to null, but I noticed that the getDuration, getCurrentTime and getSecondsLoaded methods must return a number, so TypeScript complains about this since I'm initializing these values as null. I took a look at all the players that exist in react-player and noticed that if not all, then almost all players return null in these methods and not just numbers, so I assumed that the types are not correct. Am I missing something or are the types just not correct?

luwes commented 2 months ago

yes, the types could use some refinements.

if we look at the native video element currentTime should start at 0, as does getSecondsLoaded() so those should be fine.

however duration is NaN by default which doesn't have an equivalent in TS so undefined or unknown would make sense here