Improve typings
Created by: aj-r
Fixes #2317 (closed).
- Never use the Object type. We should use object instead, or better yet, define a proper interface for those objects.
- Never use the Function type. Instead, define a more specific signature for that function.
- Changed several instances of
type: string
to more specific types (e.g.type: 'video' | 'audio'
). This way typescript can catch typos, e.g.mediaPlayer.getTracksFor('vidoe')
will cause a compile error. - Added special overloads for
on()
. This way listeners automatically get the right event type. e.g.mediaPlayer.on(MediaPlayer.events.TEXT_TRACKS_ADDED, e => { // 'e' implicitly has a type of TextTracksAddedEvent. // So the properties e.type, e.enabled, e.index, and e.tracks are available, // but any other property will raise a typescript compile error. this.tracks = e.tracks; });
- I didn't add many JSDoc comments for now to make the diff easier to read. I'll probably add them in a separate PR.