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

Helper function types are not properly exposed on main video.js namespace #8937

Open
pac96 opened this issue Dec 11, 2024 · 2 comments
Open
Labels
needs: triage This issue needs to be reviewed

Comments

@pac96
Copy link

pac96 commented Dec 11, 2024

Description

There are some helper types that are not properly exposed on the video.js namespace. For example, player.textTracks() does not have a proper type return, and in order for you to know that it returns TextTrackList, you'd need to do something like this:

import type { TextTrackList } from 'video.js/dist/types/tracks/text-track-list';

The Request:
A user, I would like to import video.js types without having to go inside the dist directory. Using the above example as a guide, I would like to do something like this:

import type { TextTrackList } from 'video.js'

For further information, please refer to the Slack thread discussing this: https://videojs.slack.com/archives/C43LGP955/p1733876135260749

Reduced test case

n/a

Steps to reproduce

  1. Use video.js in a project with Typescript enabled (for easy access, use it in a React project)
  2. Import video.js and instantiate a player object by running videojs() with necessary arguments
  3. Observe thatplayer.textTracks() causes a Typescript error and that its return value is any as a result
  4. Try adding import type { TextTrackList } from 'video.js' and observe that this type is not found

Errors

No response

What version of Video.js are you using?

8.17.4

Video.js plugins used.

No response

What browser(s) including version(s) does this occur with?

All

What OS(es) and version(s) does this occur with?

All

@pac96 pac96 added the needs: triage This issue needs to be reviewed label Dec 11, 2024
@gkatsev
Copy link
Member

gkatsev commented Dec 11, 2024

it's related to the text track apis being added dynamically and while the jsdoc is there, it isn't being added to player.d.ts:

video.js/src/js/player.js

Lines 5442 to 5473 in 19ca3f2

/**
* Get the remote {@link TextTrackList}
*
* @return {TextTrackList}
* The current remote text track list
*
* @method Player.prototype.remoteTextTracks
*/
/**
* Get the remote {@link HtmlTrackElementList} tracks.
*
* @return {HtmlTrackElementList}
* The current remote text track element list
*
* @method Player.prototype.remoteTextTrackEls
*/
TRACK_TYPES.names.forEach(function(name) {
const props = TRACK_TYPES[name];
Player.prototype[props.getterName] = function() {
if (this.tech_) {
return this.tech_[props.getterName]();
}
// if we have not yet loadTech_, we create {video,audio,text}Tracks_
// these will be passed to the tech during loading
this[props.privateName] = this[props.privateName] || new props.ListClass();
return this[props.privateName];
};
});

one potential solution is to stop applying them dynamically. But we'd want to confirm that it makes typescript happy before making that change.

@gkatsev
Copy link
Member

gkatsev commented Dec 16, 2024

There's #8486 which takes care of the specific text track types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: triage This issue needs to be reviewed
Projects
None yet
Development

No branches or pull requests

2 participants