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.

3 Answers 3

1

Based on your code sample the signature should be:

interface JQuery
{
    ajaxSubmit(arg:{error:any, success:any}): JQuery;
}
Sign up to request clarification or add additional context in comments.

3 Comments

I modified that but the error hasn't gone. The error shows up at the "$(this)" part in the code. I'm not sure if that's correct.
@EternallyCurious put a new line after the dot (this). to verify error cause
Your code actually works. The problem with $(this) was another issue.
0

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

Comments

0

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

Comments

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.