JMPerez / spotify-web-api-js

A client-side JS wrapper for the Spotify Web API
https://jmperezperez.com/spotify-web-api-js/
MIT License
1.87k stars 265 forks source link

getUserPlaylists issue with undefined userId #135

Closed neilime closed 4 years ago

neilime commented 5 years ago

I need to retrieve the first 50 playlists of current user.

Typescript definition of function getUserPlaylists : getUserPlaylists(userId?: string, options?: Object,... suggest to do : getUserPlaylists(undefined, {limit: 50});

I does not work...

Actually the function getUserPlaylists does not work as expected according to the doc and typescript typing.

If the userId is not a string (undefined or anything else), the first argument become the options.

But in typescript you cannot pass an object as the first argument because it must be a string or undefined.

EricLambrecht commented 5 years ago

I had the same issue! Since I don't use Typescript I was able to just use the first parameter as options, but my IDE is not happy of course. And for me it was very confusing figuring out why it didn't work initially.

mzbrandl commented 4 years ago

I faced the same issue. A workaround is adding // @ts-ignore before the function call.

emyann commented 4 years ago

I had the same issue, and I dug a bit in the source. Here's what I found if it could help:

I got around this issue by requesting the userId and calling getUserPlaylists(userId, { limit: 20 }) instead.