1

Hi I a m trying to do ""Autocomplete""" in TypeScript & Jquery.

 this.$("#testAuto").autocomplete({
           source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ]
           });

But the compiler can not find the autocomplete in any of the d.ts files.

 **error TS2094: The property 'autocomplete does not exist on value of type 'JQuery'.**

I am using Jquery v2.

Please help !!

2
  • Have you added the jQuery interfaces to the TypeScript project? If not, you should, otherwise the compiler won't be instructed on what the jQuery methods would return Commented Jul 16, 2013 at 10:11
  • I think I did, my other jquery functions works fine.. Commented Jul 16, 2013 at 10:29

1 Answer 1

2

You need to add a reference to the autocomplete.d.ts file e.g.:

/// <reference path="path/to/your/jquery.autocomplete.d.ts" />

Although I suspect that you are using the wrong definition file and should be using this one: https://github.com/borisyankov/DefinitelyTyped/blob/master/jqueryui/jqueryui.d.ts

It contains your required definition:

interface JQuery {
    // ...

  autocomplete(): JQuery;
  autocomplete(methodName: string): JQuery;
  autocomplete(methodName: 'close'): void;
  autocomplete(methodName: 'destroy'): void;
  autocomplete(methodName: 'disable'): void;
  autocomplete(methodName: 'enable'): void;
  autocomplete(methodName: 'search', value?: string): void;
  autocomplete(methodName: 'widget'): JQuery;
  autocomplete(options: JQueryUI.AutocompleteOptions): JQuery;
  autocomplete(optionLiteral: string, optionName: string): any;
  autocomplete(optionLiteral: string, options: JQueryUI.AutocompleteOptions): any;
  autocomplete(optionLiteral: string, optionName: string, optionValue: any): JQuery;

    // ... 
}

Update: Quick useful solution Since you are using the bootstrap version, remove the reference to jquery.autocomplete.d.ts and jqueuryUI. And just have the following block before your code:

interface JQuery{
   autocomplete(config:{source:string[];});
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hi I tired both jqueryUI, and jquery.autocomplete.d.ts....but its no use.... again bootstrap.d.ts is conflicting with jqueryUI
@user1847624 try the quick solution I posted

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.