# Problem with warnings in 7.4.1 (JSDoc?)

**URL:** https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166
**Category:** Classic Servoy
**Created:** [September 12, 2014, 6:49am UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166 "2014-09-12T06:49:30Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)
#### Post date: [September 12, 2014, 6:49am UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/1 "2014-09-12T06:49:30Z")

</div>

Hi,

I have recently upgraded to V7.4.1 and immediately got a lot of new warnings for my project regarding invalid arguments similar to:

```auto
The method sendMaill(String,String,String,String,String,String,Array<plugins.mail.Attachment>,String) in the type Plugin<mail> is not applicable for the arguments (String,String,String,String,String,String,plugins.mail.Attachment|Array<plugins.mail.Attachment>)

```

The one thing they all have in common is that there are multiple calling options for the method and the particular one I am using is definitely valid for the method in question. Further investigation shows that there are two conditions that need to be met for the warning to show up incorrectly:

1. There must be a signature matching the call you are using but with additional arguments at the end
2. The particular signature you are using comes **after** the one it complains about when you look at the code completion options

This would indicate that Servoy/Eclipse/JSDoc (not sure which is responsible) is finding the partial match for call and then immediately reporting the warning without checking the rest of the possible calling options.

Has anyone else experienced this? Should I report it as a bug?

Thanks  
Steve

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [September 12, 2014, 10:24am UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/2 "2014-09-12T10:24:51Z")

</div>

> steve1376656734:  
> plugins.mail.Attachment|Array\<plugins.mail.Attachment\>

This is the problem, you casted a variable to be either one or the other type.  
Just cast it as below and you should be good.

```auto
Array<plugins.mail.Attachment>

```

---

<div class="post-metadata">

### Author: ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)
#### Post date: [September 12, 2014, 11:09am UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/3 "2014-09-12T11:09:46Z")

</div>

Hi Marc,

I understand what you are saying and can see that all the warnings are related to functions that have at least one parameter that has been declared as multiple types. The problem I have now is that I’m not sure how to overcome it. My scenario is I am calling the plugins.mail.sendMail function that has multiple signatures two of which are:

```auto
plugins.mail.sendMail(String,String,String,String,String,String,plugins.mail.Attachment) plugins.mail.sendMail(String,String,String,String,String,String,Array<plugins.mail.Attachment>)

```

The final argument can be either a single attachment or an array of attachments. I have an intermediate routine that takes the same parameters and manipulates some of them prior to calling the plugins.mail.sendMail function and has been declared as follows:

```auto
/**
 * @param {String} param1
 * @param {String} param2
 * @param {String} param3
 * @param {String} param4
 * @param {String} param5
 * @param {String} param6
 * @param {plugins.mail.Attachment|Array<plugins.mail.Attachment>} param7
 */
function myFunc(param1, param2, param3, param4, param5, param6, param7) {
    // Do some stuff with params 1 - 6 (nothing with param 7)
    // ....
    // ....

    // Now call the mail plugin
    plugins.mail.sendMail(param1, param2, param3, param4, param5, param6, param7);
}

```

How can I modify my intermediate routine to avoid the warning as I cannot explicitly cast the last parameter as it could have been passed as either type?

The weird thing is I never got these warnings with 7.3!

Many thanks  
Steve

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [September 12, 2014, 12:00pm UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/4 "2014-09-12T12:00:51Z")

</div>

Hi Steve,

you could something like this at the top of your function:

```auto
/** @type {Array<plugins.mail.Attachment>} */
var myAttachments = [];
if(param7 !== undefined) {
     if(param7 instanceof Array) {
          myAttachments = param7;
    } else {
          myAttachments.push(param7);
    }
}

```

Now pass the myAttachments variable to the plugin function instead of directly passing param7.

---

<div class="post-metadata">

### Author: ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)
#### Post date: [September 14, 2014, 8:01pm UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/5 "2014-09-14T20:01:28Z")

</div>

Hi Marc,

Tried your suggestion and unfortunately it just moved the warning to the myAttachments.push(param7) line. However it did point me to a solution that does remove all the warnings which is:

```auto
/** @type {Array<plugins.mail.Attachment>} */
var myAttachments = [];
if(param7 !== undefined) {
     if(param7 instanceof Array) {
          myAttachments = param7;
    } else {
          /** @type {plugins.mail.Attachment} */
          var tempAttachment = param7;
          myAttachments.push(tempAttachment);
    }
}

```

This does seem rather convoluted though just to avoid a warning ![:?]( "Confused")

Thanks for your help  
Steve

---

<div class="post-metadata">

### Author: ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)
#### Post date: [September 14, 2014, 9:39pm UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/6 "2014-09-14T21:39:12Z")

</div>

Hi Steve,

> steve1376656734:  
> This does seem rather convoluted though just to avoid a warning ![:?]( "Confused")

I think there is a learning moment here.  
If you know for a fact your code is right AND efficient and the parser spouts out a warning that is clearly wrong, DON’T try to fix it and make it less efficient JUST to make the parser happy.  
Ignore the warning and file it as a bug, the warning hopefully will be going away in the next version(s).

And as I have said in many other posts. Warning are just that, warnings. Not errors. Your code will not work any worse (in 99.999% of the cases). Usually the parser is right and there is indeed something going on but sometimes it is clearly just WRONG. So ignore it and move on (and file it as a bug report).

Just my 2 cents.

---

<div class="post-metadata">

### Author: ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)
#### Post date: [September 14, 2014, 9:52pm UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/7 "2014-09-14T21:52:30Z")

</div>

Hi Robert,

Great advice and after more than 30 years in the business I find learning moments still happen every day ![:D]( "Very Happy")

That said I’m very picky and hate to see warnings in my code ![:x]( "Mad")

Steve

---

<div class="post-metadata">

### Author: ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)
#### Post date: [September 15, 2014, 11:05am UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/8 "2014-09-15T11:05:45Z")

</div>

> ROCLASI:  
> Ignore the warning and file it as a bug, the warning hopefully will be going away in the next version(s).

I’m pretty sure declarations of variables typed as ‘type A OR type B’ can’t be parsed correctly.  
(If I’m recalling the statement of Johan Compagner correctly)

> steve1376656734:  
> Tried your suggestion and unfortunately it just moved the warning to the myAttachments.push(param7) line.

Sorry Steve, my bad wrote this without consulting my own parser. ![:-)]( "Smile")

> steve1376656734:  
> This does seem rather convoluted though just to avoid a warning

I agree, though the only way to really avoid the ‘OR’ type you use is just to always pass an Array of attachments to your method.

---

<div class="post-metadata">

### Author: ![steve1376656734](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/steve1376656734/32/4613_2.png) [@steve1376656734](https://forum.servoy.com/u/steve1376656734)
#### Post date: [September 15, 2014, 1:25pm UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/9 "2014-09-15T13:25:39Z")

</div>

> mboegem:  
> I agree, though the only way to really avoid the ‘OR’ type you use is just to always pass an Array of attachments to your method.

Doh! - why didn’t I think of that. The simple solutions are always the best ![:D]( "Very Happy")

---

<div class="post-metadata">

### Author: ![jcompagner](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/jcompagner/32/4889_2.png) [@jcompagner](https://forum.servoy.com/u/jcompagner)
#### Post date: [October 23, 2014, 8:53am UTC](https://forum.servoy.com/t/problem-with-warnings-in-7-4-1-jsdoc/18166/10 "2014-10-23T08:53:20Z")

</div>

this:

```auto
/**
* @param {String} param1
* @param {String} param2
* @param {String} param3
* @param {String} param4
* @param {String} param5
* @param {String} param6
* @param {plugins.mail.Attachment|Array<plugins.mail.Attachment>} param7
*
 * @properties={typeid:24,uuid:"7BF7C4E7-C7EA-45F0-A607-32C750FBB9CC"}
 */
function myFunc(param1, param2, param3, param4, param5, param6, param7) {
    plugins.mail.sendMail(param1,param2,param3,param4,param5,param6,param7)
}

```

should work in the coming release. (at least if i try it now it works for me)
