From 96c65aaebbf9670cc4b41977ac3ea772f8f4f5e6 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sat, 16 Mar 2019 23:30:25 -0700 Subject: [PATCH] Improve typing of onTrackDidChange --- demo/js/mediaSession.ts | 2 +- index.d.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/demo/js/mediaSession.ts b/demo/js/mediaSession.ts index 1ca84c32..1f3b4c46 100644 --- a/demo/js/mediaSession.ts +++ b/demo/js/mediaSession.ts @@ -4,7 +4,7 @@ import { LoadedURLTrack } from "../../js/types"; export default function enableMediaSession(webamp: WebampLazy) { if ("mediaSession" in navigator) { /* global MediaMetadata */ - webamp.onTrackDidChange((track: LoadedURLTrack | null) => { + webamp.onTrackDidChange(track => { if (track == null) { return; } diff --git a/index.d.ts b/index.d.ts index 15252031..139edb27 100644 --- a/index.d.ts +++ b/index.d.ts @@ -45,6 +45,16 @@ interface BlobTrack extends TrackInfo { blob: Blob; } +interface LoadedURLTrack { + url: string; + metaData: { + artist: string | null; + title: string | null; + album: string | null; + albumArtUrl: string | null; + }; +} + /** * Many methods on the webamp instance deal with track. * @@ -190,7 +200,7 @@ export default class Webamp { * @returns An "unsubscribe" function. Useful if at some point in the future you want to stop listening to these events. */ public onTrackDidChange( - cb: (trackInfo: { url: string } | null) => void + cb: (trackInfo: LoadedURLTrack | null) => void ): () => void; /**