diff --git a/lib/sources/AppleMusic.ts b/lib/sources/AppleMusic.ts index 1090e90..dbeb65e 100644 --- a/lib/sources/AppleMusic.ts +++ b/lib/sources/AppleMusic.ts @@ -182,9 +182,9 @@ export default class AppleMusic extends AbstractExternalSource { }); if (res.statusCode === 200) { - return res.body.json(); + return res.body.json() as T; } else { - return new AppleMusicError(await res.body.json()); + return new AppleMusicError(await res.body.json() as IErrorResponse); } } diff --git a/lib/sources/Deezer.ts b/lib/sources/Deezer.ts index 667dcec..4bc3ce5 100644 --- a/lib/sources/Deezer.ts +++ b/lib/sources/Deezer.ts @@ -92,13 +92,13 @@ export default class Deezer extends AbstractExternalSource { } private async makeRequest(endpoint: string): Promise { - const res = await request(`https://api.deezer.com/${endpoint}`).then(r => r.body.json()); + const res = await request(`https://api.deezer.com/${endpoint}`).then(r => r.body.json()) as IDeezerResponse; if (res.error) { return new DeezerError(res.error.type, res.error.message); } - return res; + return res as T; } } @@ -116,6 +116,10 @@ class DeezerError implements IDeezerError { } } +interface IDeezerResponse { + error?: IDeezerError; +} + interface IDeezerError { type: string; message: string; diff --git a/lib/sources/Spotify.ts b/lib/sources/Spotify.ts index dc1354a..a443ebe 100644 --- a/lib/sources/Spotify.ts +++ b/lib/sources/Spotify.ts @@ -206,13 +206,13 @@ export default class Spotify extends AbstractExternalSource { headers: { Authorization: this.token as string, } - }).then(r => r.body.json()); + }).then(r => r.body.json()) as ISpotifyResponse; if (res.error) { return new SpotifyError(res.error.message); } - return res; + return res as T; } private async renewToken() { @@ -266,6 +266,10 @@ class SpotifyError implements ISpotifyError { } } +interface ISpotifyResponse { + error?: ISpotifyError; +} + interface ISpotifyError { message: string; }