Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating Typescript Typings for third party JQuery Plugins?

Tags:

typescript

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?

like image 772
JD Davis Avatar asked Feb 21 '26 07:02

JD Davis


1 Answers

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;
}
like image 113
thoughtrepo Avatar answered Feb 23 '26 00:02

thoughtrepo