![](/img/trans.png)
[英]What is the difference between the JQuery and the JQueryStatic interface in TypeScript?
[英]Do I need to declare all my JQuery prototypes in a JQueryStatic definition file with TypeScript?
我有以下代碼:
///<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);
}
};
}
當我嘗試添加以下內容時:
$('a').addTemplateSetup(
在這個文件中,我注意到沒有智能感知和打字稿似乎不了解我剛剛添加的addTemplateSetup原型。
這是工作的正確方法嗎?還是我總是需要將諸如addTemplateSetup的定義之類的內容添加到JQueryStatic定義文件中,然后將其包括在內?
您將需要以某種方式聲明它,以使Typescript不抱怨,最簡單的方法是將其聲明為any:
interface JQuery {
addTemplateSetup: any;
}
但是,要獲得最佳的智能感知支持,還請添加有關參數類型的信息:
interface JQuery {
addTemplateSetup: (func: Function, priority: bool) =>void;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.