Skip to content

refactor(types): Type enhancements#8968

Open
mister-ben wants to merge 28 commits into
videojs:mainfrom
mister-ben:type-enhancements
Open

refactor(types): Type enhancements#8968
mister-ben wants to merge 28 commits into
videojs:mainfrom
mister-ben:type-enhancements

Conversation

@mister-ben
Copy link
Copy Markdown
Contributor

@mister-ben mister-ben commented Jan 23, 2025

Several changes for Typescript.

  • Adds a jsdoc plugin to not break on @template {xyz} T. Replaces uses of T with Class.<xyz>
    • Used in component.js
  • Adds definitions for ComponentOptions, SourceObject, PlayerOptions, MediaObject
  • Removes further uses of ~ namespacing, which is valid jsdoc, but which tsc fails to understand
  • Changes track kinds to simple union types. Change the existing definitions to enums so we can use them as object lookups without conflicting with the standard definitions.
  • Use native TextTrackCue, TextTrackKind definitions.
  • Exports Player, PlayerOptions and Plugin from video.js.
    • This makes it easier to add to the object than at present e.g. in a plugin to declare module 'video.js' { interface Player {
    • This sets a precedent - what else could/should be exported at this level? Should the names be more verbose?
  • Adds additional jsdoc on for track and readyState in HTMLTrackElement, as tsc doesn't understand documentation for properties added with Object.defineProperties . Fixes HTMLTrackElement class provided missing two properties as stated in MDN #8959

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.32%. Comparing base (e27bb32) to head (ec10afa).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8968      +/-   ##
==========================================
- Coverage   84.90%   84.32%   -0.58%     
==========================================
  Files         120      120              
  Lines        8153     8155       +2     
  Branches     1964     1964              
==========================================
- Hits         6922     6877      -45     
- Misses       1231     1278      +47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/js/video.js

export default videojs;
export {
Player,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows adding to the Player interface in plugins:

declare module 'video.js' {
  interface Player {
    touchOverlay: TouchOverlay;
    touchOverlayDirect: TouchOverlay;
    mobileUi: {
      (options?: MobileUiPluginOptions): void;
      VERSION: string;
    }
  }
}

Comment thread src/js/component.js
*
*
* @return {Component}
* @return {T}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renders like this in the API docs with the changes to jsdoc-typeof-plugin:
image

@mister-ben mister-ben changed the title [WIP] Type enhancements refactor(types): Type enhancements Feb 15, 2025
@mister-ben mister-ben marked this pull request as ready for review February 15, 2025 09:32
Comment thread build/jsdoc-typeof-plugin.js Outdated
Comment thread src/js/component.js Outdated
@dasa
Copy link
Copy Markdown

dasa commented Jul 7, 2025

Is it possible that this PR will also fix #9059?

@mister-ben mister-ben added the needs: LGTM Needs one or more additional approvals label Jan 5, 2026
Comment thread src/js/player.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: LGTM Needs one or more additional approvals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTMLTrackElement class provided missing two properties as stated in MDN

3 participants