0

I am calling a Typescript function passing a string and a function as parameters to it. But I have an error possibly because of syntactical mistakes.

Calling code:

send(
            {
                num: value,
                file: fileData
            },
            function(responseData){
                alert('Successfully uploaded : ' + responseData + " and received ");
            }
        );

Called function:

function send(data : String, success: Function){
    $.ajax({
        type: 'POST',
        data: JSON.stringify(data),
        contentType: 'application/json',
        url: '/testData',
        success: function (responseData) {
            return JSON.parse(responseData);
            success(responseData);
        },
        error: function(error){
            return null;
        }
    });
}

Error:

C:/Users/Me/AppData/Roaming/npm/tsc.cmd --sourcemap Start.ts --module commonjs --out main.js
C:/Users/Me/WebstormProjects/Core/public/javascripts/Start.ts(54,9): error TS2082: Supplied parameters do not match any signature of call target:
    Type '{ num: any; file: any; }' is missing property 'charAt' from type 'String'.
C:/Users/Me/WebstormProjects/Core/public/javascripts/Start.ts(54,9): error TS2087: Could not select overload for 'call' expression.

1 Answer 1

1

No syntax error. The error message says it all: the object you pass (as the first argument) does not have the right type. (The function expects a String.)

Sign up to request clarification or add additional context in comments.

2 Comments

What data type should I provide to pass a JSON. Consider the passed data as the correct, type and the definition as incorrect.
Change your method signature to function send(data : any, success: Function){

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.