Reputation: 3720
I was attempting to write a D.TS file for a third party JQuery UI element I found. However, I can't quite seem to wrap my head around it.
After looking at other definition files, they all seem to work for items that are more akin to standalone libraries, but not plugins per-say.
The plugin I'm working with can be found here. But I've yet to find any typings for it. Has anyone worked with something similar?
Upvotes: 3
Views: 1611
Reputation: 276105
A quick definition file e.g. bootstrapToggle.d.ts
would containing the following :
interface JQuery {
bootstrapToggle: any;
}
Upvotes: 0
Reputation: 8383
The definition file for the jQuery Transit plugin is a good example of what you're looking for.
For plugins, first the jQuery definition from Definitely Typed should be referenced:
/// <reference path="../jquery/jquery.d.ts"/>
Then the plugin can be defined on the existing JQuery
interface. The plugin you linked would look something like this:
interface JQueryBootstrapToggleOptions {
on?: string;
// [...]
height?: number;
}
interface JQuery {
bootstrapToggle(options?: JQueryBootstrapToggleOptions): JQuery;
bootstrapToggle(method?: "destroy"): JQuery;
// [...]
bootstrapToggle(method?: "disable"): JQuery;
bootstrapToggle(method?: string): JQuery;
}
Upvotes: 6