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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type define the root hls.js #2200

Merged
merged 9 commits into from May 25, 2019
Merged

Type define the root hls.js #2200

merged 9 commits into from May 25, 2019

Conversation

itsjamie
Copy link
Collaborator

This PR will...

Add Type definitions to the hls.js file. 馃巻

Why is this Pull Request needed?

Starting to work outside-in for Typescript definitions.

Are there any points in the code the reviewer needs to double check?

There was a single actual behaviour change:

(config.liveSyncDuration === void 0 || config.liveMaxLatencyDuration <= config.liveSyncDuration)
swapped from
(config.liveMaxLatencyDuration <= config.liveSyncDuration || config.liveSyncDuration === void 0)

I don't think there is ever a reason to check the undefined case second?

Resolves issues:

No, but work toward #2070.

Checklist

  • changes have been done against master branch, and PR does not conflict
  • API or design changes are documented in API.md

Also configured the TS compiler to emit declaration files to `dist/declarations`.

Also, for a canary build this includes package.json `"types"` key to point at the declarations.
This should be removed before merging this branch as we do NOT want to ask regular users to use our typing data yet until it is more complete than DT.
Copy link
Member

@tjenkinson tjenkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃帀

src/hls.ts Outdated Show resolved Hide resolved
src/hls.ts Outdated Show resolved Hide resolved
src/hls.ts Show resolved Hide resolved
@tjenkinson
Copy link
Member

Also we could add the types property to the package.json

@itsjamie
Copy link
Collaborator Author

itsjamie commented Apr 1, 2019

Also we could add the types property to the package.json

Yeah, I had it in there and removed it because the types aren't better than the DefinitelyTyped typings yet, so I don't want to make the usage harder until they're more complete.

itsjamie and others added 2 commits March 31, 2019 21:59
Implementing PR feedback from tjenkinson.

Co-Authored-By: Tom Jenkinson <tom@tjenkinson.me>
@itsjamie
Copy link
Collaborator Author

itsjamie commented Apr 1, 2019

I either have to stop doing stuff on Windows or take the time to figure out how to properly set up a Windows dev environment. Little things like lint exploding with CRLF errors and the like.. :(

@itsjamie
Copy link
Collaborator Author

itsjamie commented Apr 4, 2019

Let me know if there is anything keeping this out!

Copy link
Member

@michaelcunningham19 michaelcunningham19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 馃憤

johnBartos
johnBartos previously approved these changes Apr 10, 2019
src/hls.ts Show resolved Hide resolved
}

/**
* @type {QualityLevel[]}
*/
get levels () {
// todo(typescript-levelController)
Copy link
Collaborator

@robwalch robwalch Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @itsjamie,

I just started working on this in the jwplayer fork (LHLS branch) jwplayer/hls.js@LHLS...jwplayer:feature/typescript-level-and-track-controllers#diff-b071dfbf3f116515dee94f5b36c35a2aR16

I think it's a great idea to actually start with these changes since the hls player instance is referenced in all controllers, and we can decide whether certain getters should be nullable or return -1 in the case of number getters.

It seems that -1 was the default for most number getters until maybe recently. When I set up an Hls instance without loading anything, the results are mixed:

Screen Shot 2019-04-17 at 1 24 06 PM

Any thoughts, preferences or concerns?

Copy link
Collaborator Author

@itsjamie itsjamie Apr 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if possible documenting current state would be helpful as TypeScript for the users who don't want to move to a 1.0.0 with the breaking changes. This is definitely seperate from the work I know you guys have done at JWPlayer, and I wouldn't ask you to change yours to document current state that won't be valid soon. I also wouldn't want to hold up progress just to add typing when the refactor already exists, so I think this concern is invalid.

@johnBartos @michaelcunningham19 @tjenkinson What do you guys think about targeting 1.0.0 as the cut-off for when we start publishing TypeScript library files from hls.js?

If we do the above ^, then it comes down to a decision of what do we want the API to be. It also means we don't have to worry about the intermittent state for many of the controllers @robwalch.

if (hls.subtitleTrack) { }, or if (hls.subtitleTrack !== -1) or some variant of this with a set const?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've covered more ground jwplayer/hls.js@LHLS...jwplayer:feature/typescript-level-and-track-controllers

firstLevel (showing NaN above) is the only getter I've changed the default for by giving it an initial value and strongly typing it. We have to be careful with some properties like startLevel which is also a config value where both undefined and -1 already mean something different (default first in manifest vs auto abr selection).

I'm not looking to shake things up in our fork or do any major refactoring with the typing here - no initially. The only changes would be when there are clearly errors, or it's clear that stronger typing benefits us. There's no point in just slapping any everywhere and calling it typed. Further down the line I'd want to look more carefully at what is nullable, optionally assigned or allowed to be undefined to see how to reduce the risk associated with transient properties.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsconfig.json Outdated Show resolved Hide resolved
The npm run build:types runs tsc with the CLI flag on.
@itsjamie
Copy link
Collaborator Author

itsjamie commented May 7, 2019

John confirmed in Slack he had tested the IE concerns and it was good.

@itsjamie itsjamie merged commit 6d71a5e into master May 25, 2019
@itsjamie itsjamie deleted the typescript-publicapi branch May 25, 2019 19:39
@itsjamie itsjamie added this to In progress in Typescript Integration Aug 28, 2019
@itsjamie itsjamie moved this from In progress to Done in Typescript Integration Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants