I'm using Twilio.js library on my application (not Twilio Node) and there's no module nor typings for this library available. There's only a Twilio
global variable available that one can use.
The simplest ambient declaration one can have to avoid errors in the IDE is this:
declare const Twilio: any;
But I want to go a little bit further and for that I've been reading TypeScript handbook and few other resources. I've taken especially attention to this link.
And here's what I have so far:
declare const Twilio: Twilio.Base;
declare namespace Twilio {
export interface Base {
Device: Device;
}
export interface Device {
ready(handler: DeviceCallback): void;
}
export interface DeviceCallback {
(device: Device): void;
}
}
This is working, but it's just a sample, it's not complete. As an example, it suffices for now :)
But my question is three-fold:
- Given the short sample above, would you do anything differently?
- If I remove the
export
keyword from all interfaces, it still works. Should I still leave it? What does it do? Given the usage
Twilio.Device.ready(this.handleTwilioDeviceReady.bind(this));
, IDEs give me the following when hovering my mouse over:Twilio
:const Twilio: Twilio.Base
Twilio.Device
:(property) Twilio.Base.Device: Twilio.Device
Twilio.Device.ready
:(method) Twilio.Device.ready(handler: Twilio.DeviceCallback): void
How can I get rid of
Twilio.Base
showing up in the IDE and instead show:Twilio
:const Twilio: Twilio
Twilio.Device
:(property) Twilio.Device: Twilio.Device