Typescript definitions for all exports
See original GitHub issueCurrent 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
- 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
- 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:
- Created 3 years ago
- Reactions:10
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @JuanM04. Awesome work on the PR. I’m just looking through it now.
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
I don’t use Typescript, but I welcome any PRs that add definitions to the codebase in a clean way.