简体   繁体   English

从TypeScript创建Javascript类的实例

[英]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. 我正在尝试从Typescript调用javascript类,但是编译器(VS)却出现了摆动。

The class itself is InfoBox but unfortunately I cannot find a typescript definition for it. 该类本身是InfoBox,但是不幸的是我找不到它的打字稿定义。

When I try to use it from my TS class it complains that it cannot find name "InfoBox" 当我尝试从TS类使用它时,它抱怨找不到名称“ 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 prototype method like so 在InfoBox.js文件中,它是使用prototype方法定义的,如下所示

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

You can declare the class yourself, for example in a file InfoBox.d.ts : 您可以自己声明类,例如在文件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 . 声明文件的文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM