The method indexOf() is undefined

After importing a 6.0.8 solution into 6.1.2, I’m getting lots of these warnings in situations like:

var position = -1;
var tempText = "";
position = tempText.indexOf(";");

The warning that appears is,

The method indexOf() is undefined for object tempText

In the same vein, it is also unhappy with the subsequent line,

aSTplanType_10 *= tempText.substring(0 , position);*
*```*
*...and the warning that appears is*
*> The method substring() is undefined for object tempText*
*Has anyone experienced this?*
*Thank you,*
*Don*

Hi Don,

not seen this, as far as I can remember…

what happens when you the below JSDoc above the var temText declaration?

/** @type {String} */

I have seen this warning a lot of times. It disappears if you comment the declaration with JSDoc as suggested by mboegem

rioba:
I have seen this warning a lot of times. It disappears if you comment the declaration with JSDoc as suggested by mboegem

Of course it helps, but why does Servoy need it in the first place?

var tempText = “” should be enough indicator that we’re talking ‘String’ here…

Hi Mark and rioba,

Yes, inserting that @type declaration made the errors go away. Thank you for that tip!

I agree with Mark. Why has this warning message been added? To remove hundreds of warnings, must I now go through thousands of lines of code, finding every instance of “tempText”, to add an unnecessary type declaration?

Is it best practice to place the @type declaration right above the variable being typed, or is it better to place all the declarations in the header?

I also have a bunch of warnings on lines like this:

if(dsSummary.getValue(j,1) == distSvc_code) {

…generates this warning:

The function getValue(Number,Number) is not applicable for the arguments (None,Number)

A similar warning occurs with dsSummary.setValue, e.g.,

dsSummary.setValue(j,5,dsSummary.getValue(j,5) + 1); 

The variable j is defined at the top of the method as “j = 0;”. Based on Mark’s tip, I successfully added,

/** @type {number} j */

…which resolved the problem. But I always define these loop variables by setting them to zero. Shouldn’t that be sufficient?

Thank you,
Don

do not add those kind of type declarations.

var tmpTxt = “”;

should be seen as a String. what could go wrong is that you reuse that same variable also for more things (like a number) then it can be that it doesn’t know exactly what it is.

in servoy 6.1.4 there will be quite a lot of fixes for the code completion/validation.

I use tempText repeatedly, but it’s always a text container. It’s not used for numbers.

If you have an example what does go wrong in 6.1.3, that i can just drop into a js file on my workspace (or a sample solution) then i can check it how it works in the current code.

I’m not sure what you mean. The solution that I sent with the last bug report does illustrate the issue with tempText, in the browse_form.js file.

Thank you,
Don

that that browse_form.js i see 3 times: tempText.indexOf and in the current code it doesn’t complain on any of those 3 lines, so i guess if that was a problem, it is fixed now