disable unresolved variable on json object received by ajax call

Hi,

when using a jquery ajax call like this, I get un unresolved method field
because data is not declared as an object with method field

but data is a value set through ajax call, so I cannot declare it's structure in advance


how do I disable the code inspector warning n a situation like this ?


$.ajax({
            type: form.attr('method'),
            url: form.attr('action'),
            data: form.serialize(),

            success: function (data, status, xhr) {


             console.log(data.field)


}
)

thanks

4 comments
Comment actions Permalink

Hello!

I can suggest creating a fake variable that will hold this json value,  and use this var as a value of @type annotation to let WS know what the  actual type is. Smth like:


var jsontext = {"field":"val"};
$.ajax({

    type: form.attr('method'),

    url: form.attr('action'),
    /**
     * @type {jsontext}
     */
    data: form.serialize(),

    success: function (data, status, xhr) {

        console.log(data.field)

    }}  )

-2
Comment actions Permalink

Elena, I've a similar problem and .... your solution works fine but I get another waring: unused local variable on 'jsontext'

0
Comment actions Permalink

@Elena, that is a pretty weird solution. Why not just use a namespace declaration?

$.ajax({
  type: form.attr('method'),
  ...,
  success: function (data, status, xhr) {
    /** @namespace data.field **/
    console.log(data.field)
  }
});

-1
Comment actions Permalink

You can use whatever solution you like - create your own stubs (https://youtrack.jetbrains.com/issue/WEB-17419#comment=27-1058451), use different JSDoc annotations, etc.

0

Please sign in to leave a comment.