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.86k stars 260 forks source link

Typings for spotify-api #190

Open half2me opened 3 years ago

half2me commented 3 years ago

This is probably just me not knowing typescript enough, but I've been trying now for hours unsuccessfully.

I want to type a variable to SpotifyApi.TrackObjectFull[]

Basically after calling this.spotify.getTracks(...), I'm assigning the result to a variable, and I need to type it. In my IDE, I can see the return type of the function is a Promise<SpotifyApi.MultipleTracksResponse> inside of which is the tracks key, which has the type: TrackObjectFull[];

All I would like to do is to be able to define my variable like so:

let myTrack: TrackObjectFull[]

However I'm unable to resolve this type from anywhere. Its doesn't seem to be exported from the 'spotify-web-api-js' module. I even tried npm i --save-dev @types/spotify-api to see if I could import it somehow from there, but when I try to import it, it says its not a module. I can see that the IDE picks up on the type, but I really need to use it as well. What do I need to import for it to work?

Thank you for your help.

snigle commented 3 years ago

Hello, I had the same issue and I found typescript lib : https://github.com/adamgrieger/spotify-web-api-ts