[英]External JavaScript dependencies in Typescript
I have read a few Q/A on here on how to use external libraries in TS. 我已经在这里阅读了一些有关如何在TS中使用外部库的问题。 Following a lot of the suggestions, I'm registering BT alert to an element like this:
遵循很多建议,我正在将BT警报注册到这样的元素:
import * as $ from "jquery";
import * as bootstrap from 'bootstrap';
window["$"] = $;
window["jQuery"] = $;
$("#clientAlert").alert();
and everything work just fine. 而且一切正常。
Now I need to do the same for JQuery-Ticker 现在我需要对JQuery-Ticker做同样的事情
import * as jqueryTicker from "jquery-ticker";
$('.newsticker').ticker();
WebPack build fails with this error: WebPack构建因以下错误而失败:
error TS2339: Property 'ticker' does not exist on type 'JQuery'.
错误TS2339:类型“ JQuery”上不存在属性“ ticker”。
尝试这个 :
($(".newsticker") as any).ticker();
You could cast it to <any>
or extend the jquery typing to add your own method. 您可以将其强制转换为
<any>
或扩展jquery类型以添加自己的方法。
(<any>$(".newsticker")).ticker();
//Or add your own custom methods (Assuming this is added by yourself as a part of custom plugin) //或添加您自己的自定义方法(假设此方法是您自己添加为自定义插件的一部分)
interface JQuery {
newsticker():void;
}
Or this 或这个
($(".newsticker") as any).ticker();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.