Chris Chris - 1 year ago 132
TypeScript Question

Creating an instance of a Javascript class from TypeScript

I am trying to call a javascript class from Typescript but the compiler (VS) is throwing a wobbly.

The class itself is InfoBox but unfortunately I cannot find a typescript definition for it.

When I try to use it from my TS class it complains that it cannot find name "InfoBox"

public showInfoWindow(latLng: google.maps.LatLng, map: google.maps.Map): InfoBox {
var infobox = new InfoBox({
// ...

return infobox;

In the InfoBox.js file it is defined using the
method like so

function InfoBox(opt_opts) { ... }
InfoBox.prototype = new google.maps.OverlayView();

Answer Source

You can declare the class yourself, for example in a file InfoBox.d.ts:

// InfoBox.d.ts
declare class InfoBox {
    constructor(obj: any);
    // Here the members of InfoBox you use

The documentation on declaration files is here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download