Skip to content

Commit

Permalink
Integrated typescript typings (JMPerez#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
skovmand authored and JMPerez committed Oct 20, 2016
1 parent c1e17c6 commit 335140d
Show file tree
Hide file tree
Showing 6 changed files with 8,720 additions and 7 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,22 +296,33 @@ spotifyApi.getUserPlaylists() // note that we don't pass a user id
});
```

## Typings for Typescript
## Integrated Typescript Typings

Get typings for this package and all responses from Spotify API endpoints from the DefinitelyTyped repository by installing the typescript definition manager ```tsd``` from npm like so:
Get great code completion for this package using the integrated typescript typings. It includes the complete typings of the Spotify Web Api too, so you'll know both how to the navigate the API as well as the response you are getting.

$ npm install -g tsd
![Typings Example](https://raw.githubusercontent.com/JMPerez/spotify-web-api-js/master/typings-example.gif)

Then in the directory in which you want the typings directory, run this command to install both the definitions for this library and the definitions for The Spotify Web API.
### When bundling the library

$ tsd install spotify-web-api-js
If you are bundling spotify-web-api-js using e.g. webpack you can include the library and the typings into a typescript file like this:

Then reference the typings from the top of your main .ts file with
```typescript
import * as SpotifyWebApi from 'spotify-web-api-js';

let spotify = new SpotifyWebApi();
```
/// <reference path="../typings/spotify-web-api-js/spotify-web-api-js.d.ts"/>

### When using the library globally

If you are using the library globally, for example including directly from index.html, include the typings in the top of your typescript file. Typescript will then assume the library is already present globally. Adjust the path to ```node_modules```.

```typescript
/// <reference path="../node_modules/spotify-web-api-js/src/typings/spotify-web-api.d.ts" />

let spotify = new SpotifyWebApi();
```


## Running tests

In order to run the tests, run:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"name": "José M. Pérez"
},
"main": "src/spotify-web-api.js",
"typings": "src/typings/spotify-web-api.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/JMPerez/spotify-web-api-js"
Expand Down
Loading

0 comments on commit 335140d

Please sign in to comment.