typescript html ui,jQuery UI widgets in TypeScript

邴星洲
2023-12-01

You also need to include jquery.d.ts in order to access and manipulate typed jQuery objects. This will allow you to access your slider in the typical jQuery way. For example:

/* Initialize slider with ID 'my_slider'. */

$("#my_slider").slider({

min: 0,

max: 100,

value: 0,

change: (event: Event, ui) => {

/* Update as desired. */

}

});

In this example, the type for $('#my_slider') is defined in jquery.d.ts, and all the relevant slider functions and such are defined in jqueryui.d.ts.

Just to finish off the example, in your HTML, you'll want something like:

EDIT: I think this is a bug. Even with the following:

var my_slider : JQueryUI.Slider = $('#my_slider').slider;

my_slider.slide({

...

})

It still doesn't register the type information for slide.

Here's a hack-ish fix. Replace the SliderUIParams interface (line 442 in jqueryui.d.ts) with an actual interface:

interface SliderUIParams {

value: number;

values?: number[];

handle: JQuery;

}

Then, in your slider call, statically type your arugments, e.g.:

slide: (event: Event, ui: JQueryUI.SliderUIParams) => {

...

}

 类似资料:

相关阅读

相关文章

相关问答