8

There are many threads for similar issues, but as far as I can tell this one is unique.

I'm using jQuery Address plugin in my app and would like to use it in a TypeScript file. Unfortunately there is no DefinitelyTyped script available for the library. When I try to use jQuery.address, I get:

The property 'address' does not exist on value of type 'jQueryStatic'

Per this thread, I've tried to define address inside of jquery.d.ts:

interface JQueryStatic {
    address(options): any;
    ...
}

And I think this seems to work for $.address(); but not for any of address' methods. I've also tried to create my own .d.ts file per this thread, but still no luck. And I tried using declare in a .d.ts file. No luck.

The only method that I need to use is the parameter method...

$.address.parameter('param', 1);

In which case I get:

The property 'parameter' does not exist on value of type 'address'

Any ideas on how I can resolve this?

edit: I'm working in a Visual Studio C# .net environment, if that helps.

Community
  • 1
  • 1
dmathisen
  • 2,269
  • 3
  • 36
  • 63

2 Answers2

11

You should not need to edit jquery.d.ts itself; put these definitions in their own file so they can be maintained properly. Something minimal would be like this:

// For methods on e.g. $('a')
interface JQuery {
    address(callback?: () => void): JQuery;
}

// For methods on $
interface JQueryStatic {
    address: JQueryAddressStatic;
}

interface JQueryAddressStatic {
    (): JQuery;
    parameter(name: string): string;
    parameter(name: string, value: string, append?: boolean): JQuery;
}
Ryan Cavanaugh
  • 209,514
  • 56
  • 272
  • 235
3

The following goes inside jquery.d.ts:

interface JQueryStatic {
    address(options): JQueryAddress;
}

interface JQueryAddress {
    parameter(name, value): any;
}

Hope that helps!

Aashish Koirala
  • 448
  • 5
  • 12
  • Thanks. That solved the 'address' issue but I still get "The property 'parameter' does not exist on value of type 'address'". So $.address() works, but $.address.parameter() doesn't. – dmathisen Aug 07 '13 at 21:16
  • 2
    Don't edit existing .d.ts file to add interface members -- interfaces are open and can be extended by simply declaring another interface block of the same name. – Ryan Cavanaugh Aug 07 '13 at 21:37