Reputation: 7850
I have a @types (typings) wrapper for a javascript library I use. I'd like to use a constructor (new
) and instance and then use it, but I'm confused on whether the type definition for the library even supports it, and if it doesn't what the proper syntax is to start using the library through the type definitions provided.
Here's the link to the type definition package
To be brief, there is an interface I want to use that seems to have a constructor defined via another interface
interface Mailgun { ... }
interface MailgunExport {
new (options: ConstructorParams): Mailgun;
... }
I want to do something like the following:
var mgClient : Mailgun = new Mailgun(...);
But I don't think that's exactly how it works. I'm writing a Node app in Typescript and want to stick to type definitions wherever possible (as opposed to plan javascript).
Does the type definition file as it's defined allow me to actually construct an object using new
or is it just adding types on top of the javascript API?
Upvotes: 2
Views: 173
Reputation: 250326
You can do it but the you will need the import module = require("module")
syntax to import the module since its export is defined using export=
.
You can read more in the docs here.
This will work as expected;
import Mailgun = require('mailgun-js')
var mgClient = new Mailgun({
});
Upvotes: 2