What does “WARNING - Suspicious code. The result o

2019-06-17 03:26发布

问题:

"WARNING - Suspicious code. The result of the 'getprop' operator is not being used."

I'm seeing this for two lines in my JavaScript code when I use the closure compiler. They are typedefs in among other typedefs that don't report issues. What should I be looking for?

EDIT

Affected code:

/**
 * @typedef {{playerId: number, playerName: string, baseScores: Array.<number>, bonusScores: Array.<number>,
 *          teamScoreAdjustments: Array.<number>}}
 */
wias.GameTableTeamMember;

/**
 * @typedef {{id: number, teamMembers: Array<wias.GameTableTeamMember>, teamName: string}}
 */
wias.GameTableTeam;

/**
 * @typedef {{id: number, availableRound: boolean, bonusScoring: boolean, complete: boolean, gameLength: number,
 *          gameType: string, lastPlayed: string, numberOfRounds: number, teams: Array.<wias.GameTableTeam>, winners:
 *          Array.<string>}}
 */
wias.GameTable;

Warning:

wias.js:77: WARNING - Suspicious code. The result of the 'getprop' operator is not being used.
wias.GameTableTeam;
^

Why a warning there and not elsewhere?

回答1:

It means that you have code which does nothing.

Typedef's (or record types) are more tricky for the compiler to point to the exact spot where the issue is, but somewhere you are getting a value which is not being used.

some reading about the type system and what works best with the compiler https://docs.google.com/document/d/1Uq_vNyPZjlRvYZJclX6N37Fjsiah4XNciEPSBfFiREs/edit

and to recreate the warning simply

if (true) {
   //have nothing in here
}