2
votes

I just upgraded to TypeScript 0.9 and all of a sudden my JQuery definition file (for JQuery 1.8) has exploded. Specifically, the interface JQuery is reporting an error on every single method defined within. They all report "All properties must be subtypes of string indexer type 'HTMLElement'.

interface JQuery {

    ajaxComplete(handler: any): JQuery;
    ajaxError(handler: (event: any, jqXHR: any, settings: any, exception: any) => any): JQuery;
    ajaxSend(handler: (event: any, jqXHR: any, settings: any, exception: any) => any): JQuery;
    ajaxStart(handler: () => any): JQuery;
    ajaxStop(handler: () => any): JQuery;
    ajaxSuccess(handler: (event: any, jqXHR: any, settings: any, exception: any) => any): JQuery;
    ... //All reporting same error
}

As you might expect, the JQuery interface is defined in many different files across my project. Is this a bug with unifying the interfaces or am I missing some change that needs to be made to the definition files?

1

1 Answers

6
votes

This is not a bug. Its a planned feature. This is because once you have an indexer defined, it can be used to access properties as well and therefore properties need to be subtypes of the indexer. e.g.:

interface Foo{
    [x:string]:number; // Now all properties must be subtypes of number 
    bar:number ; // okay 
    baz:string ; // Error  
}

Try It

You can find working Jquery definitions here : https://github.com/borisyankov/DefinitelyTyped/blob/master/jquery/jquery.d.ts