Reputation: 1722
I am trying to use Node-Geocoder in my typescript application, using the DefinitelyTyped type definitions found here. What I am wondering is how I am supposed to pass my configuration options to the Node-Geocoder instance. I would think you use it similar to how you use the library in Javascript, by passing the options to the constructor of the Geocoder object. However, that is giving me an error stating that the constructor does not take any arguments.
import DomainServiceInterface from "./../DomainServiceInterface";
import NodeGeocoder from "node-geocoder";
import LocationServiceInterface from "./LocationServiceInterface";
export default class LocationService implements DomainServiceInterface, LocationServiceInterface {
private geocoder: NodeGeocoder.Geocoder;
constructor() {
const options: NodeGeocoder.BaseOptions = {
provider: "google",
// other options
};
this.geocoder = new NodeGeocoder.Geocoder(options);
}
// other methods here
}
I attempted to look this up. However, all tutorials and content I could find related to Node-Geocoder are in Javascript.
What am I doing wrong?
Upvotes: 1
Views: 1799
Reputation: 2439
Fair warning, I've never used the node-geocoder package.
If you look at the type definitions, the export is a function, not a class. (Technically declaration merging is used to export a function and a namespace.) That function takes Options
and instantiates a Geocoder
instance.
That said, you would create a Geocoder
like this.
import * as NodeGeocoder from 'node-geocoder';
const options: NodeGeocoder.Options = {
provider: "google",
};
const geoCoder = NodeGeocoder(options);
Upvotes: 3