jqgrid declaration

Topics: General
Oct 3, 2012 at 8:12 PM

I'm trying to write a partial declaration for JQGrid, but I'm having trouble with the following method :

interface JQuery {
    getInd(rowid: string): bool;
    getInd(rowid: string): number;
}


getInd definition states:
 This method returns the index of the row in the grid table specified by id= rowid when rowcontent set to false (default). If rowcontent is set to true, it returns the entry row object. If the rowid can not be found, the function returns false

probably the only way to model this is to return any ?
because now, when I try to use it with the above definition

var hasIndex:bool = grid.getInd(rowid);

I get an error,  Ambigous call expression...

Is there a better way than using any as return type? 

Coordinator
Oct 3, 2012 at 8:22 PM

This is a good question for the general forums rather than language specification (which is more about what features are needed in the language).

For your example, because the compiler doesn't know what will be returned when getInd is called, it's best to use 'any'.  Using overloaded function signatures works best for functions that return different types for different argument types:

interface JQuery {
    getInd(rowid: bool): bool;
    getInd(rowid: number): number;
}