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

Feature request: add Typescript typings #4

Open
ChristiaanScheermeijer opened this issue May 16, 2022 · 6 comments
Open

Feature request: add Typescript typings #4

ChristiaanScheermeijer opened this issue May 16, 2022 · 6 comments
Labels
enhancement New feature or request triaged

Comments

@ChristiaanScheermeijer
Copy link

I would like to use this component in a Typescript project. It would be nice if typings could be added to the package so it becomes easier to use in Typescript projects.

Thanks in advance!

@m1is
Copy link

m1is commented Aug 30, 2022

I would like to use this component in a Typescript project. It would be nice if typings could be added to the package so it becomes easier to use in Typescript projects.

Thanks in advance!

How do you go about adding typings? I'm unable to use the package because of this.

@ChristiaanScheermeijer
Copy link
Author

We are not using this package yet. Although, I was able to use it in a typescript project. Perhaps I did use some @ts-ignore's 😅

@m1is
Copy link

m1is commented Aug 30, 2022

We are not using this package yet. Although, I was able to use it in a typescript project. Perhaps I did use some @ts-ignore's 😅

I ended up just creating a .jsx file instead.

@imbcmdth imbcmdth added the enhancement New feature or request label Jan 19, 2023
@bb441db
Copy link

bb441db commented Mar 22, 2023

Add types for jwplayer

yarn add -D @types/jwplayer

Create file jwplayer-react.d.ts with the following:

declare module '@jwplayer/jwplayer-react' {
    import React from 'react';

    /**
     * Example: {"2500":"High","1000":"Medium"}
     */
    type QualityLabels = Record<string, string>

    type Stretching = 'uniform' | 'exactfit' | 'fill' | 'none';

    /**
     * Width in pixels or percentage
     */
    type Width = number | string;

    interface AppearanceConfig {
        aspectratio?: string;
        controls?: boolean;
        displaydescription?: boolean;
        displayHeading?: boolean;
        displayPlaybackLabel?: boolean;
        displaytitle?: boolean;
        height?: number;
        horizontalVolumeSlider?: boolean;
        nextUpDisplay?: boolean;
        qualityLabels?: QualityLabels;
        renderCaptionsNatively?: boolean;
        stretching?: Stretching;
        width?: Width;
    }

    type AutoStart = 'viewable';
    /**
     * A positive value is an offset from the start of the video.
     * A negative value is an offset from the end of the video.
     * This property can be defined either as a number (-10) or a percentage as a string ("-2%")
     */
    type NextUpOffset = string | number;

    interface BehaviorConfig {
        aboutlink?: string;
        abouttext?: string;
        allowFullscreen?: boolean;
        autostart?: AutoStart;
        defaultBandwidthEstimate?: number;
        generateSEOMetadata?: boolean;
        liveSyncDuration?: number;
        mute?: boolean;
        nextupoffset?: NextUpOffset;
        pipIcon?: string;
        playbackRateControls?: boolean;
        playbackRates?: number[];
        playlistIndex?: number;
        repeat?: boolean;
    }
    
    type MediaType = 'aac' | 'f4a' | 'f4v' | 'hls' | 'm3u' | 'm4v' | 'mov' | 'mp3' | 'mp4' | 'mpeg' | 'oga' | 'ogg' | 'ogv' | 'vorbis' | 'webm';

    interface MediaConfig {
        file?: string;
        description?: string;
        image?: string;
        mediaid?: string;
        title?: string;
        type?: MediaType;
    }

    type Preload = 'metadata' | 'auto' | 'none';

    interface RenderAndLoadingConfig {
        base?: string;
        flashplayer?: string;
        hlsjsdefault?: boolean;
        liveTimeout?: number;
        loadAndParseHlsMetadata?: boolean;
        preload?: Preload;
    }

    export type JWPlayerConfig = AppearanceConfig & BehaviorConfig & MediaConfig & RenderAndLoadingConfig;

    export interface JWPlayer extends jwplayer.JWPlayer {

    }

    export interface DidMountCallbackArguments {
        id: string;
        player: JWPlayer;
    }

    type DidMountCallback = (arguments: DidMountCallbackArguments) => void;

    export interface JWPlayerProps extends JWPlayerConfig {
        didMountCallback?: DidMountCallback;
        willUnmountCallback?: () => void;
        id?: string;
        library: string;
        config?: JWPlayerConfig;
    }

    const JWPlayerComponent = React.Component<JWPlayerProps & React.HTMLProps<'video'>>;

    export default JWPlayerComponent;
}

Based on the documentation from JWPlayer and the code in this repository

@jwbrandon
Copy link

@bb441db Can you submit a pull request for this?

@dimbslmh
Copy link

dimbslmh commented May 5, 2023

Thanks @bb441db, looks like the above typings is only covering the Setup Options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triaged
Projects
None yet
Development

No branches or pull requests

6 participants