Help fixing "inconsistent return type" warning

158 views
Skip to first unread message

Ben McCann

unread,
Dec 15, 2012, 11:45:20 PM12/15/12
to closure-comp...@googlegroups.com
I'm getting a warning trying to compile some JS:

angular.js:366: WARNING - inconsistent return type
found : *
required: boolean
return obj && obj.document && obj.location && obj.alert && obj.setInterval;

I'm surprised this is causing a warning. What's the preferred way to do this with Closure Compiler?

Thanks,
Ben

Ilia Mirkin

unread,
Dec 15, 2012, 11:52:14 PM12/15/12
to closure-comp...@googlegroups.com
This will actually return false or obj.setInterval (which is not a
boolean), hence the confusion. You can do

return Boolean(obj && ...);

Which should coerce it to a boolean.

Ben McCann

unread,
Dec 15, 2012, 11:57:07 PM12/15/12
to closure-comp...@googlegroups.com
Ah, true. Thanks
--
about.me/benmccann

John Lenz

unread,
Dec 16, 2012, 1:24:52 PM12/16/12
to closure-comp...@googlegroups.com

I usually use "!!"

Reply all
Reply to author
Forward
0 new messages