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

TypeScript: Property 'on' does not exist on type 'Player' #8109

Closed
jdufresne opened this issue Feb 5, 2023 · 10 comments
Closed

TypeScript: Property 'on' does not exist on type 'Player' #8109

jdufresne opened this issue Feb 5, 2023 · 10 comments
Labels
bug needs: triage This issue needs to be reviewed

Comments

@jdufresne
Copy link
Contributor

Description

The TypeScript definitions are missing the methods added by the EventedMixin on the Player class.

Reduced test case

https://github.com/jdufresne/video-js-test

Steps to reproduce

Files: test.ts

import videojs from "video.js";

const videoEl = document.createElement("video");
const player = videojs(videoEl, {
  sources: [{ src: "https://vjs.zencdn.net/v/oceans.mp4", type: "video/mp4" }],
});
player.on("ended", () => {
  console.log("video ended");
});

Compiling this TypeScript results in the following error:

$ npx tsc
test.ts:7:8 - error TS2339: Property 'on' does not exist on type 'Player'.

7 player.on("ended", () => {
         ~~

Errors

test.ts:7:8 - error TS2339: Property 'on' does not exist on type 'Player'.

What version of Video.js are you using?

8.0.3

Video.js plugins used.

none

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

n/a

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

n/a

@jdufresne jdufresne added bug needs: triage This issue needs to be reviewed labels Feb 5, 2023
@video-archivist-bot
Copy link

Hey! We've detected some video files in a comment on this issue. If you'd like to permanently archive these videos and tie them to this project, a maintainer of the project can reply to this issue with the following commands:

@welcome
Copy link

welcome bot commented Feb 5, 2023

👋 Thanks for opening your first issue here! 👋

If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.
To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@boris-petrov
Copy link
Contributor

These are the things that I found missing from the v8 types compared to the v7 ones:

On the Player type: controlBar, readyState, bigPlayButton, remoteTextTracks, audioTracks, on, one, off, trigger

player.ready should set the this of the function in the first argument to be the player instance.

On Tech: on, off

AudioTrackList should extend AudioTrack[].

TextTrackList should extend TextTrack[].

@insilications
Copy link

The v8 types/typing is very incomplete too.

@Quimy
Copy link

Quimy commented Feb 9, 2023

In my case, there was a change in typings from separate package @types/video.js to types in videojs itself and it lacks many of the types:

  • there is no Player class exposed, previously it was VideoJsPlayer
  • custom components show errors:
const VjsButton = videojs.getComponent('Button');
class FrameControlButton extends VjsButton {
  private frameSkipTime: number;

  constructor(player: VideoJsPlayer, options: { [key: string]: never } = {}) {
    super(player, options);
    this.frameSkipTime = options.frameSkipTime;
  }

  handleClick() {
    this.player().currentTime(this.player().currentTime() + this.frameSkipTime);
  }
}

Type 'Component' is not a constructor function type.
Property 'player' does not exist on type 'FrameControlButton'

@horans
Copy link

horans commented Feb 13, 2023

Similar problem here, use to have following import in v7 with @types/video.js:

import videojs, { type VideoJsPlayer, type VideoJsPlayerOptions } from 'video.js'

Now with v8, I got errors and fail to build:

Module '"video.js"' has no exported member 'VideoJsPlayer'.
Module '"video.js"' has no exported member 'VideoJsPlayerOptions'.

@boris-petrov
Copy link
Contributor

@Quimy, @horans - I use import type Player from 'video.js/dist/types/player'; for that.

@Quimy
Copy link

Quimy commented Feb 14, 2023

@boris-petrov Thanks, it helped with missing player type.

For the other problem I used workaround:
const VjsButton = videojs.getComponent('Button') as unknown as typeof Button;

I think the signature for getComponent and registerComponent is wrong. It should accept class instance instead of expecting class object, or am I wrong?

ahnanne added a commit to krafton-jungle-AI-InterviewMate/AI-InterviewMate-FE that referenced this issue Mar 3, 2023
@weiz18
Copy link
Contributor

weiz18 commented Mar 15, 2023

We have similar issue on 8.2.0 as well and we have to use import type VideoJsPlayer from 'video.js/dist/types/player'; .
are they meant to be resolved?

Errors ->
Property 'controlBar' does not exist on type 'Player'
This expression is not constructable.Type 'Component' has no construct signatures.

@jdufresne
Copy link
Contributor Author

My original issue is resolved with the latest release, so closing. If others are still seeing typing issues, I recommend opening a separate issue with an example.

Thanks for the fix!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug needs: triage This issue needs to be reviewed
Projects
None yet
Development

No branches or pull requests

7 participants