elements icon indicating copy to clipboard operation
elements copied to clipboard

Bug: Mismatch between docs, TS types, and behavior for cuepoints and chapters

Open decepulis opened this issue 7 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Which Mux Elements/Packages does this apply to? Select all that apply

mux-player-react

Which browsers are you using?

Safari

Which operating systems are you using?

macOS

Description

The types described in the docs don't match up with the types in TypeScript for addCuePoints and addChapters in @mux/mux-player-react

Reduced test case

https://codesandbox.io/p/sandbox/dreamy-pascal-637nl9?file=%2Fsrc%2FApp.tsx%3A9%2C45

Steps to reproduce

Cue points

  • Try passing an object with type { startTime: number; endTime?: number; value: any; } to addCuePoints. TypeScript yells (even though this type is in the Mux Docs).
  • Try passing an object with type { time: number; value: any } to addCuePoints. TypeScript does not yell (even though this type is not in the Mux Docs)

Chapters

  • Try passing an object with type { startTime: number; endTime?: number; value: any; } to addChapters. TypeScript yells (even though this type is in the Mux Docs).
  • Try passing an object with type { startTime: number; endTime: number; value: any; } to addChapters. TypeScript does not yell.

Current Behavior

Cue points

  • Docs say { startTime: number; endTime?: number; value: any; }
  • TS types say addCuePoints<T = any>(cuePoints: { time: number; value: T; }[]): Promise<TextTrack | undefined>;
  • I'm using { time: number; value: any } and it's working as expected

Chapters

  • Docs say { startTime: number; endTime?: number; value: any; }
  • TS types say addChapters(chapters: { startTime: number; endTime: number; value: string; }[]): Promise<TextTrack> | undefined;. (Notice that endTime is required in TS)
  • I'm using { startTime: number; value: string } and it's working as expected

Expected Behavior

I'm assuming the docs are correct here. So...

Cue Points

  • TS should say addCuePoints<T = any>(cuePoints: { startTime: number; endTime?: number; value: T; }[]): Promise<TextTrack | undefined>;
  • And maybe { time: number; value: T } should be supported as a legacy option, since that's how Cue Points used to work, right?

Chapters

  • TS types should say addChapters(chapters: { startTime: number; endTime?: number; value: string; }[]): Promise<TextTrack> | undefined;

Errors

image image

What version of the package are you using?

2.8.0

decepulis avatar Jul 12 '24 19:07 decepulis