videojs / video.js

Video.js - open source HTML5 video player
https://videojs.com
Other
37.85k stars 7.43k forks source link

Typescript for "VideoJsPlayerOptions" on version 8.10.0 #8646

Open Rafaelmf opened 5 months ago

Rafaelmf commented 5 months ago

Description

Hello!

I had the video.js version 7.19.2 running on a react project and I was getting the VideoJsPlayerOptions type as: import { VideoJsPlayerOptions } from "video.js"

After updating to the new version 8.10.0 this is not exported anymore. And I couldn't find it anywhere. Can someone help me with that? I get the error: Module '"video.js"' has no exported member 'VideoJsPlayerOptions'. Did you mean to use 'import VideoJsPlayerOptions from "video.js"' instead?

Below is the type on previous versions:

export interface VideoJsPlayerOptions extends videojs.ComponentOptions {
    aspectRatio?: string | undefined;
    autoplay?: videojs.Autoplay | undefined;
    bigPlayButton?: boolean | undefined;
    controlBar?: videojs.ControlBarOptions | false | undefined;
    textTrackSettings?: videojs.TextTrackSettingsOptions | undefined;
    controls?: boolean | undefined;
    defaultVolume?: number | undefined;
    fill?: boolean | undefined;
    fluid?: boolean | undefined;
    height?: number | undefined;
    html5?: any;
    inactivityTimeout?: number | undefined;
    language?: string | undefined;
    languages?: { [code: string]: videojs.LanguageTranslations } | undefined;
    liveui?: boolean | undefined;
    loop?: boolean | undefined;
    muted?: boolean | undefined;
    nativeControlsForTouch?: boolean | undefined;
    notSupportedMessage?: string | undefined;
    playbackRates?: number[] | undefined;
    playsinline?: boolean | undefined;
    noUITitleAttributes?: boolean | undefined;
    plugins?: Partial<VideoJsPlayerPluginOptions> | undefined;
    poster?: string | undefined;
    preload?: videojs.Preload | undefined;
    responsive?: boolean | undefined;
    sourceOrder?: boolean | undefined;
    sources?: videojs.Tech.SourceObject[] | undefined;
    src?: string | undefined;
    techOrder?: string[] | undefined;
    tracks?: videojs.TextTrackOptions[] | undefined;
    userActions?: videojs.UserActions | undefined;
    width?: number | undefined;

    audioOnlyMode?: boolean | undefined;
    audioPosterMode?: boolean | undefined;
    autoSetup?: boolean | undefined;
    breakpoints?: Partial<videojs.Breakpoint> | undefined;
    fullscreen?: { options: { navigationUI: "hide" } } | undefined;
    id?: string | undefined;
    liveTracker?: {
        trackingThreshold?: number | undefined;
        liveTolerance?: number | undefined;
    } | undefined;
    normalizeAutoplay?: boolean | undefined;
    preferFullWindow?: boolean | undefined;
    restoreEl?: boolean | Element | undefined;
    suppressNotSupportedError?: boolean | undefined;
    techCanOverridePoster?: boolean | undefined;
    "vtt.js"?: string | undefined;
    disablePictureInPicture?: boolean | undefined;
    enableSourceset?: boolean | undefined;
    retryOnError?: boolean | undefined;
}

Reduced test case

https://codepen.io/gkatsev/pen/GwZegv?editors=1000#0

Steps to reproduce

  1. Just minimal setup with react
  2. Get typings for options argument

Errors

No response

What version of Video.js are you using?

8.10.0

Video.js plugins used.

No response

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

Chrome

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

Macos

welcome[bot] commented 5 months ago

šŸ‘‹ 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.

try2beth3b3st commented 5 months ago

Same question.. Why no options types in d.ts..(

victordidenko commented 4 months ago

Also videojs function accepts any as options now

declare function videojs(id: string | Element, options?: any, ready?: ReadyCallback): Player;
dparker2 commented 4 months ago

So version 8 exports its own types but they are way more incomplete than the community-made DefinitelyTyped ones for v7? Why not copy/paste the DefinitelyTyped ones and work from there??

victordidenko commented 1 week ago

@marcosATr did you try it? It is any

image
iliawx commented 1 week ago

As a work around:

import videojs from 'video.js'
type VideoJsPlayerOptions = Parameters<typeof videojs>[1]
victordidenko commented 1 week ago

@iliawx I don't understand, are you kidding?

image
marcosATr commented 1 week ago

@victordidenko , I'm sorry I provided the wrong import. I deleted the previous comment to avoid further confusion. Here's how you can get the proper type for video.js options parameter:

import videojs from "video.js/dist/video.min";

type PlayerOptions = typeof videojs.options;
type AlsoPlayerOptions = Parameters<typeof videojs>["1"];

image

Here's a sandbox where you can explore the types.

victordidenko commented 1 week ago

@marcosATr I understand now, but this is hardly proper type. In your sandbox types are defined in @types/video.js@7.3.58 package, which might be incompatible with version 8. And more, it might break a runtime build, if video.js package will change internal structure. They can do it any time, even in patch release, because it is not a breaking change in terms of semantic versioning.