Using places.js with typescript

I’m trying to use places.js in a React/Typescript project. I figured out that there are types in the DefinitelyTyped project and am trying to use them with no luck. The problem seems to be that while the places library is called “places.js” the types are referred to simply as “places”. So when I try to do:

import places from 'places.js';

it tells me that it could not find a declaration file. When I try to do:

import places from 'places'

my text editor is happy but the compiler says:

Module not found: Can't resolve 'places'

I also tried to just copy the declarations from the DefinitelyTyped repo and change things to refer to places.js, but it seems like the dot in the middle of the name is causing syntax errors. I feel pretty confident that there’s something dumb I’m missing here, but would love some help.

I figured out how to do this locally by creating my own declarations file. I will need to add to this to get the full interface but to start it will work with:

/// <reference types="node" />

declare module 'places.js' {
  interface PlacesOptions {
    appId: string;
    apiKey: string;
    container: string | HTMLInputElement | NodeList | Element;
  }

  declare function places(options: PlacesOptions): EventEmitter;
  export default places;
}

It seems like the stuff in DefinitelyTyped is unusable because the name of the package is incorrect, and it should be changed to places.js.

Hi @aubrey,

Thanks for reporting the issue (and your solution).

As these typings are maintained by the Community inside the DefinitelyTyped repo, feel free to log an issue or submit a PR to the DefinitelyTyped repo with these changes.

Best regards,

As it happens, there is already a PR in DefinitelyTyped to address the issue:

At the moment it looks really close to ready for a merge, so hopefully this will be fixed for real soon.