question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript definitions for all exports

See original GitHub issue

Current Behavior

Typescript definitions for the individual players (react-player/wistia, react-player/youtube, etc…) are missing.

e.g.,

import WistiaPlayer from "react-player/wistia";
...

// JSX element type 'ReactPlayerWistia' does not have any construct or call signatures.ts(2604)
<WistiaPlayer ... /> 

As a result, I need to either

  1. explicitly add my own type declarations, and paint WistiaPlayer with the broad typedefs of ReactPlayer…
// react-player/index.d.ts
declare module "react-player/wistia" {
  import ReactPlayer from "react-player";
  export default ReactPlayer;
}

which isn’t exactly great because now props such as onBuffered, onBufferEnded, onEnablePIP, etc… that WistiaPlayer really doesn’t support noop and creates a confusing developer experience,

OR

  1. again explicitly add my own type declarations, but completely type out the WistiaPlayer export + props that actually work and don’t noop.
// react-player/index.d.ts
declare module "react-player/wistia" {
    import * as React from "react";
    import ReactPlayer from "react-player";

    type WistiaConfig = {
        wistia: {
            // https://wistia.com/support/developers/embed-options#options
            options?: {
                ...
            };
            playerId?: string;
        };
    };

    export type ReactPlayerWistiaProps = {
        url?: string | string[];
        playing?: boolean;
        loop?: boolean;
        controls?: boolean;
        volume?: number;
        muted?: boolean;
        playbackRate?: number;
        width?: string | number;
        height?: string | number;
        style?: React.CSSProperties;
        progressInterval?: number;
        light?: boolean | string;
        wrapper?: keyof JSX.IntrinsicElements;
        config?: WistiaConfig;
        className?: string;
        onReady?(player: ReactPlayer): void;
        onStart?(): void;
        onPlay?(): void;
        onPause?(): void;
        onEnded?(): void;
        onError?(
            error: any,
            data?: any,
            hlsInstance?: any,
            hlsGlobal?: any
        ): void;
        onDuration?(duration: number): void;
        onSeek?(seconds: number): void;
        onProgress?(state: { played: number; playedSeconds: number }): void;
    };
    export default class ReactPlayerWistiaPlayer extends React.Component<
        WistiaPlayerProps,
        any
    > {
        static canPlay(url: string): boolean;
        static canEnablePIP(url: string): boolean;
        static addCustomPlayer(player: ReactPlayer): void;
        static removeCustomPlayers(): void;
        seekTo(amount: number, type?: "seconds" | "fraction"): void;
        getCurrentTime(): number;
        getDuration(): number;
        getInternalPlayer(key?: string): Object;
        showPreview(): void;
    }
}

Expected Behavior

Expect that if I use any of the other exports (react-player/wistia, react-player/youtube, etc…) they’re automatically typed and I don’t need to create my own typings for them.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
cookpetecommented, Dec 8, 2020

Hey @JuanM04. Awesome work on the PR. I’m just looking through it now.

When I import the react-player/wistia, should the config attribute equal to { wistia: { … } } or { … }?

As of v2.0.0, both are supported due to this crazy merging:

https://github.com/cookpete/react-player/blob/d47aa03ffc0902977038401b0604d87a7fe712f1/src/ReactPlayer.js#L120-L128

2reactions
cookpetecommented, Jul 3, 2020

I don’t use Typescript, but I welcome any PRs that add definitions to the codebase in a clean way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Modules .d.ts - TypeScript
The types which are exported can then be re-used by consumers of the modules using either import or import type in TypeScript code...
Read more >
How to export/import a only a type definition in TypeScript
In flowtype this would look like this: The file sub.js export the type myType using export type myType = {id: number}; and the...
Read more >
How to export a Type in TypeScript | bobbyhadz
Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported...
Read more >
Typescript definitions for all exports · Issue #953 - GitHub
Current Behavior Typescript definitions for the individual players (react-player/wistia, react-player/youtube, etc...) are missing.
Read more >
Example of TypeScript Export Function - eduCBA
Definition of TypeScript Export Function ... In TypeScript we can almost export anything using the 'export' keyword. It is not a function rather...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found