如何停止“类型为JQuery的属性不存在"?使用Typescript时出现语法错误? [英] How can I stop "property does not exist on type JQuery" syntax errors when using Typescript?

查看:60
本文介绍了如何停止“类型为JQuery的属性不存在"?使用Typescript时出现语法错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中仅使用一行jQuery:

I am only using one line of jQuery in my application:

$("div.printArea").printArea();

但这给我一个打字稿错误:

But this is giving me a Typescript error:

JQuery类型上不存在'printArea'属性吗?

The property 'printArea' does not exist on type JQuery?

有人可以告诉我如何阻止此错误的出现吗?

Can someone tell me how I can stop this error appearing?

推荐答案

您可以将其强制转换为<any>或扩展jquery类型以添加​​您自己的方法.

You could cast it to <any> or extend the jquery typing to add your own method.

 (<any>$("div.printArea")).printArea();

//或添加您自己的自定义方法(假设此方法是您自己添加为自定义插件的一部分)

//Or add your own custom methods (Assuming this is added by yourself as a part of custom plugin)

interface JQuery {
    printArea():void;
}

这篇关于如何停止“类型为JQuery的属性不存在"?使用Typescript时出现语法错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆