Hello there,
I'm currently getting data from spotify's api through a function I have named GetSongsFromPlaylist (https://api.spotify.com/v1/playlists/). when I have gotten the data I need to check if the data I want exists, but is it possible to do it without these massive if statements?
if (
typeof formData.get('countryCode') !== 'string' ||
typeof formData.get('playlist') !== 'string'
) {
return false;
}
const playlistData: unknown = await GetSongsFromPlaylist(
formData.get('countryCode') as string,
formData.get('playlist') as string
);
if (
typeof playlistData !== 'object' ||
!playlistData ||
!('tracks' in playlistData) ||
typeof playlistData.tracks !== 'object' ||
!playlistData.tracks ||
!('items' in playlistData.tracks) ||
!playlistData.tracks.items ||
!Array.isArray(playlistData.tracks.items)
) {
return false;
}
const songIds = playlistData.tracks.items.map((item: unknown) => {
if (
typeof item === 'object' &&
item &&
'track' in item &&
typeof item.track === 'object' &&
item.track &&
'id' in item.track
) {
return item.track.id;
}
})
