2

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 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It should be mentioned that only indexers with a string key are affected by this limitation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.