What does “WARNING - Suspicious code. The result of the 'getprop' operator is not being used.” mean?

☆樱花仙子☆ 提交于 2019-12-08 16:45:56

问题


"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
}


来源:https://stackoverflow.com/questions/9124442/what-does-warning-suspicious-code-the-result-of-the-getprop-operator-is-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!