0

I'm trying to convert this JQuery plugin to typescript:

http://malsup.com/jquery/form/#download

But I'm not able to get Intellisense to recognize the function in typescript. I just need one function from the this plugin - "ajaxSubmit". I've declared it i a .d.ts file in my typescript project and added a reference to it from the main file. However, Webstorm does not seem to know that function and throws an error. Here's the .d.ts

interface JQuery
{
    ajaxSubmit(error:any, success:any): JQuery;
}

I've taken a look at this page and tried to follow the intruction in there.

Using jQuery plugin in TypeScript

Here's the program that implements AjaxSubmit. Webstorm throws an error that says: $(this) : Argument does not match parameters.

var $form = $("#fileUploadForm");
    $form.submit(function (e) {
        // perform client side validations if any

        $(this).ajaxSubmit({
            error: function () {
                // handle error
            },

            success: function (response) {
                // handle success
            }
        });

        // Important: stop event propagation
        return false;
    });

By the way, I'm using NodeJS + ExpressJs in the back end, I dont think it concerns this question.

Community
  • 1
  • 1
EternallyCurious
  • 2,345
  • 7
  • 47
  • 78

3 Answers3

1

Based on your code sample the signature should be:

interface JQuery
{
    ajaxSubmit(arg:{error:any, success:any}): JQuery;
}
basarat
  • 261,912
  • 58
  • 460
  • 511
0

Changing "$(this)" to "$form" or just "this" works.

EternallyCurious
  • 2,345
  • 7
  • 47
  • 78
0

Nuget has a TypeScript definition for the jquery forms plugin: http://www.nuget.org/packages/jquery.form.TypeScript.DefinitelyTyped/

Jonathan Moffatt
  • 13,309
  • 8
  • 51
  • 49