frenchie
frenchie

Reputation: 51997

Closure Compiler Warning on Object.keys

I have a line of code that looks like this:

var ObjectLength = Object.keys(SomeObject).length;

I need the number of keys in the object. With this line, I get the following warning:

WARNING - actual parameter 1 of Object.keys does not match formal parameter found : (Object|null)

What do I need to change in my code to remove the warning?

Upvotes: 0

Views: 347

Answers (1)

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

Closure-Compiler believes that SomeObject could potentially be null and is warning you about this. Ensure the value passed in can never be null:

var ObjectLength = Object.keys(SomeObject || {}).length;

Upvotes: 4

Related Questions