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

Typescript Typings incomplete - usage of generic typing #4197

Open
5 tasks done
Darkwinde opened this issue Jun 1, 2023 · 2 comments
Open
5 tasks done

Typescript Typings incomplete - usage of generic typing #4197

Darkwinde opened this issue Jun 1, 2023 · 2 comments
Assignees
Milestone

Comments

@Darkwinde
Copy link

Darkwinde commented Jun 1, 2023

Environment
  • Link to playable MPD file: N/A
  • Dash.js version: 4.7.0
  • Browser name/version: Chromium M47
  • OS name/version: Tizen 3.0
Steps to reproduce
  1. Embed Dash.js into a Typescript project
  2. Try to use functions and properties with generic typings like "object" and "any"
Observed behavior

It is not possible to access the returned values directly, it is always required to cast which costs significant resources on low end TV sets as well as the developer cannot be sure that the casted values and types are correct.

Examples:
getStreamsFromManifest(manifest: object): StreamInfo[];
getSupportedKeySystemsFromContentProtection(cps: object[]): object[];
getEventsForPeriod(period: Period): any[];

Expected behavior

There must be no generic typing used as this will annul the type safety of Typescript. Required casts cost resources on low end devices. With correct typing the developer is always sure to process data in the correct way.

My personal important typing requested to be implement:

  • getQualityFor(type: MediaType): number;
    • Return is typed as number but is an object
    • Return value must be typed like:
      export interface QualityInfo { absoluteIndex: number; bitrate: number; height: number; isTopBitrate: boolean; mediaInfo: MediaInfo; mediaInfoIndex: number; qualityIndex: number; representationId: string; scanType: string; width: number; }
  • getBitrateInfoListFor(type: MediaType): BitrateInfo[];
    • Return type does not fit, should be QualityInfo[] as returned object has structure like "QualityInfo" instead of "BitrateInfo".
  • getPeriodbyId(id: string): object | null;
  • getCurrentRepresentationSwitch(type: MediaType): ICurrentRepresentationSwitch;
  • Interface "ICurrentRepresentationSwitch" must define the "to" attribute
  • Interface "ICurrentRepresentationSwitch" defines "mt" attribute as Date but is number
  • getCurrentBufferLevel(type: MediaType): number;
  • getAdaptationForType(periodIndex: number, type: MediaType, streamInfo: object): object | null;
    • Return value is completely untyped and is a nested object

I tried to update the index.d.ts as far as possible, but you should have a full review on this especially as I do not know which parameter can be optional. I also like to recommend that you revise the Typescript typing in general not to have generic types offered anymore.

Adapted index.d.ts: https://github.com/Dash-Industry-Forum/dash.js/files/11624486/index.d.ts.zip

@Darkwinde Darkwinde added the Bug label Jun 1, 2023
@dsilhavy
Copy link
Collaborator

dsilhavy commented Jun 4, 2023

@Darkwinde Can you issue a pull request for your changes?

@Darkwinde
Copy link
Author

Darkwinde commented Jun 5, 2023

Hi @dsilhavy, sure.

Hope I did it right: #4200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Selected for Development
Development

No branches or pull requests

3 participants