Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use from Typescript code #9

Open
second-string opened this issue May 11, 2021 · 0 comments
Open

Unable to use from Typescript code #9

second-string opened this issue May 11, 2021 · 0 comments

Comments

@second-string
Copy link

Hey,

I'm trying to use this .js npm package from within a .ts, but there some way that the exports are set up that it's really not liking.

The default setup of this library in a regular node.js file run from the command line:

const sfm = require("setlistfm-js");

console.log(sfm.prototype);
var client = new sfm({
    key: process.env.SETLIST_FM_API_KEY,
    format: "json"
});
console.log(client);

That first console.log(sim) prints [Function: SetlistFmApi]. The second one, console.log(client) prints:

SetlistFmApi {
  key: false,
  format: 'application/json',
  language: 'en',
  getArtist: [Function (anonymous)],
  getArtistSetlists: [Function (anonymous)],
  getCity: [Function (anonymous)],
  searchArtists: [Function (anonymous)],
  searchCities: [Function (anonymous)],
  searchCountries: [Function (anonymous)],
  searchSetlists: [Function (anonymous)],
  searchVenues: [Function (anonymous)],
  getSetlistByVersion: [Function (anonymous)],
  getSetlist: [Function (anonymous)],
  getUser: [Function (anonymous)],
  getUserAttended: [Function (anonymous)],
  getUserEdited: [Function (anonymous)],
  getVenue: [Function (anonymous)],
  getVenueSetlists: [Function (anonymous)]
}

Perfect! Everything looks good there. Now here's the same example from within typescript (note the slightly different import syntax).

import sfm = require("setlistfm-js");

console.log(sfm);
const client = sfm({
    key : process.env.SETLIST_FM_API_KEY,
    format : "json",
    language : "en",
});
console.log(client);

Here, the first log output is identical to the .js one, so I know the same correct thing is getting pulled in and it's actually reading the js source (since it prints out SetlistFmApi). The second one is undefined though. So something to do with how javascript handles its default exports compared to typescript gets the wires crossed somewhere in there.

I've used js libraries with typescript before, so I know it can be done. I just don't know enough about the package ecosystem of both to know what's messed up here. Any thoughts? Happy to put up a PR if you can just point me in the direction of a cross-compatible fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant