1

I have the following code:

function submitSuccessAccess() {
    $(".accessLink")
        .attr("data-disabled", "no");
    window.location.reload();
}

I am trying to call this function like this:

submitSuccessAccess();

However I get a red underline under submitSuccessAccess saying: supplied parameters do not match any signature of call target. Seems like the submitSuccessAccess is expecting:

(eventObject: JQueryEventObject) => any

I found a temporary solution. I define and use as follows:

function submitSuccessAccess(any) {
    $(".accessLink")
        .attr("data-disabled", "no");
    window.location.reload();
}
submitSuccessAccess(null);

Am I the only one to experience anything like this?

2 Answers 2

2

Because of a bug in typescript.

Try specifiying the return type of your function to change the function definition with the definition found in jQuery.d.ts of:

jqueryevent(handler: (eventObject: JQueryEventObject) => any): JQuery;

Where jqueryevent is like click,bind, ect.

Your definition could be:

function submitSuccessAccess():void {
    $(".accessLink")
        .attr("data-disabled", "no");
    window.location.reload();
}

And probably your calling context was something like this:

$(selector).click(function() {
    submitSuccessAccess();
});

Which was initialized by somthing like this:

$(document).ready(function() {
    initSubmitAccessFunction();
})
Sign up to request clarification or add additional context in comments.

1 Comment

@Nicktar Hopefully my edit has improved the formatting a bit.
0

The actual code for your function could be:

function submitSuccessAccess(eventObject: JQueryEventObject) {
    $(".accessLink")
        .attr("data-disabled", "no");
    window.location.reload();
}

If you don't like supplying the parameter you might change the relevant line in the jquery.d.ts file

(eventObject: JQueryEventObject) => any

to

(eventObject?: JQueryEventObject) => any

which it should probably have been like this in the first place.

1 Comment

Thanks for your help but can you explain to me. Why would it default to being (eventObject: JQueryEventObject)? All I want to do is to call one function with no parameters but it seems like the JQueryEventObject is being passed or expected.

Your Answer

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