Eclipse:类型不匹配:无法从String []转换为any

Bet*_*ide 18 javascript eclipse

Eclipse抱怨我的JavaScript代码:

在此输入图像描述

正如我所知,代码工作正常.我有什么需要改变才能摆脱警告?

mac*_*ost 19

The semantic validator (despite it's failings, like this one) actually has a lot of uses. For instance, it can tell you when you've got a variable that's not being used anywhere (eg. because you have a typo in the variable's name).

If you don't want to see that error message, but you still want to keep semantic validation on, you can use this hack:

var textArray = 0 || [ ...
Run Code Online (Sandbox Code Playgroud)

it's a little ugly, and your non-Eclipse-using co-workers may not like it, but at least it gives you a way to ditch the warning and still have the benefits of the validator.

A similar hack (if you don't like the first one, or if you're a big Douglas Crockford fan) that will also work is:

var textArray;
textArray = [ ...
Run Code Online (Sandbox Code Playgroud)

  • 对于我来说,这绝对是一个比关闭语义验证更好的选择.同意虽然有验证错误,但在许多情况下它肯定是有用的.'0 ||' 诀窍解决了我发现的各种侥幸错误. (2认同)

ale*_*oot 15

似乎是WTP的错误,更具体地说是JS Validator组件的错误,默认情况下配置为"启用JavaScript语义验证".

尝试从首选项页面关闭语义验证.