我想在使用 TypeScript 的 Web 应用程序中使用 jQuery Tools 库中的Scrollable UI 工具。不幸的是, DefinitelyTyped GitHub 存储库上没有相应的定义文件,我创建了自己的:
/// <reference path="./jquery-1.8.d.ts"/>
declare module JQueryTools {
interface ScrollableOptions {
clonedClass?: string;
disabledClass?: string;
easing?: string;
items?: string;
keyboard?: any; // boolean or string
circular?: any // boolean
next?: string;
prev?: string;
speed?: number;
vertical?: any; // boolean
}
interface ScrollableUIParams {
}
interface ScrollableEvent {
(event: Event, ui: ScrollableUIParams): void;
}
interface ScrollableEvents {
onBeforeSeek?: ScrollableEvent;
onSeek?: ScrollableEvent;
onAddItem?: ScrollableEvent;
}
interface Scrollable extends ScrollableOptions, ScrollableEvents {
}
}
interface JQuery {
scrollable(): JQuery;
scrollable(methodName: string): JQuery;
scrollable(options: JQueryTools.ScrollableOptions): JQuery;
scrollable(optionLiteral: string, optionName: string): any;
scrollable(optionLiteral: string, options: JQueryTools.ScrollableOptions): any;
scrollable(optionLiteral: string, optionName: string, optionValue: any): JQuery;
}
在我的 .ts 文件中,我有以下调用:
$(".scrollableWrapper").scrollable({vertical: true});
在编译时,我收到以下错误:
error TS2094: The property 'scrollable' does not exist on value of type 'JQuery'.
如果我从定义文件中删除所有代码并将其粘贴到 jquery-1.8.d.ts 文件中,一切似乎都可以正常工作,没有编译错误。那么,我的问题是:为什么我的定制 d.ts 文件没有被 typescript 编译器拾取?