Skip to content

Instantly share code, notes, and snippets.

@richseviora
Created February 22, 2017 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richseviora/7479889d210014b57d2d75da2b78ec16 to your computer and use it in GitHub Desktop.
Save richseviora/7479889d210014b57d2d75da2b78ec16 to your computer and use it in GitHub Desktop.
Twilio Example
namespace Twilio {
Device = {
setup: function () { },
ready: function () { },
offline: function () { },
incoming: function () { },
connect: function (params): Twilio.Connection { return null },
error: function () { }
}
}
namespace NodeJS {
interface Global {
Twilio : {
Device : Twilio.IDevice;
};
}
}
beforeEach(() => {
Twilio.Device.setup = () => {return null;};
})
test('adds stuff', () => {
expect(Twilio.Device).toBeTruthy()
expect(Twilio.Device.setup(null, null)).toBeNull()
})
declare namespace Twilio {
class Connection {
// Constructor does not appear to be available to user.
private constructor();
// Add Connection Methods and Properties Here
}
type DeviceCallback = (device : IDevice) => void;
// Not immediately clear if Twilio.Device is a class or not.
interface IDevice {
setup(token, options);
ready(handler: DeviceCallback) : void;
offline(handler : DeviceCallback) : void;
error(handler : DeviceCallback) : void;
incoming(handler);
connect(params) : Connection;
// Add Remainder of Twilio.Device properties here.
}
/**
* Twilio.Device appears to be a singleton object that
* you don't instantiate yourself. You can use
* the below to declare its presence.
*/
let Device : IDevice;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment