Typescript with jQuery UI Widgets - Call Signature Implementation

I have many dialogs on my site (login dialog, registration dialog, contact dialog, etc.) that I am trying to simulate using Typescript.

The jquery-ui d.ts file defines the Dialog interface as such:

interface Dialog extends Widget, DialogOptions, DialogEvents{ } 

Everything in DialogOptions and DialogEvents is optional, so there is no problem, but the Widget interface defines some call signatures that I don’t understand:

 interface Widget { (methodName: string): JQuery; (options: WidgetOptions): JQuery; (options: AccordionOptions): JQuery; (optionLiteral: string, optionName: string): any; (optionLiteral: string, options: WidgetOptions): any; (optionLiteral: string, optionName: string, optionValue: any): JQuery; (name: string, prototype: any): JQuery; (name: string, base: Function, prototype: any): JQuery; } 

When I try to implement this interface in a class:

 class LoginDialog implements Dialog { } 

The compiler complains:

 Class 'LoginDialog' declares interface 'Dialog' but does not implement it: Type 'Dialog' requires a call signature, but Type 'LoginDialog' lacks one. 

I don’t understand how to implement these “signature signatures” or what they should do, in fact, I don’t even understand what a call signature is.

EDIT:

I found one type of valid use case for signing a call to enter text:

 interface ICallback{ (param: string) : void; } function someMethod(callback: ICallback){ callback('a string'); //Good callback(5); //Bad } 

However, the question still persists, since I could not find a precedent for several call signatures and still do not understand how to implement the jquery-ui.d.ts dialog interface

+4
source share
1 answer

If you are using the jQuery UI, you do not need to implement any of these interfaces, as they are already implemented in the jQuery user interface. These interfaces simply give you type information that will be used to call existing jQuery functions with static typing.

 $( "#dialog" ).dialog(); 

Without jquery-ui.d.ts , the type system will not know about the dialog() function, for example.

+5
source

All Articles