[英]Do I need to declare all my JQuery prototypes in a JQueryStatic definition file with TypeScript?
I have the following code: 我有以下代码:
///<reference path="../typescript/jquery.d.ts" />
function addThemePrototypes() {
var templateSetup = new Array();
$.fn.addTemplateSetup = function(func, prioritary)
{
if (prioritary)
{
templateSetup.unshift(func);
}
else
{
templateSetup.push(func);
}
};
}
When I try to add the following: 当我尝试添加以下内容时:
$('a').addTemplateSetup(
Into this same file I notice there is no intellisense and typescript does not seem to know about the addTemplateSetup prototype that I just added. 在这个文件中,我注意到没有智能感知和打字稿似乎不了解我刚刚添加的addTemplateSetup原型。
Is this the correct way for it to work or do I always need to add things like the definition for addTemplateSetup to an JQueryStatic definition file and then include that? 这是工作的正确方法吗?还是我总是需要将诸如addTemplateSetup的定义之类的内容添加到JQueryStatic定义文件中,然后将其包括在内?
You will need to declare it in some way to make Typescript not complain, the easiest is to declare it as any: 您将需要以某种方式声明它,以使Typescript不抱怨,最简单的方法是将其声明为any:
interface JQuery {
addTemplateSetup: any;
}
But to get best intellisense support add info about the parameter types aswell: 但是,要获得最佳的智能感知支持,还请添加有关参数类型的信息:
interface JQuery {
addTemplateSetup: (func: Function, priority: bool) =>void;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.