When coding in JS, I rely on both the google-closure compiler and jsLint tool. The closure compiler requires proper JSDoc tags to avoid errors, which means I often need to cast variables to the correct type. The code below works fine with no compiler warnings, but when running jsLint, I receive a 'Weird assignment' error. Is there an alternative way to cast variables?
/** @return {Town|Village|Park|Metropolis} */
var getCurrentItem = function() {...some code}
var item = getCurrentItem();
if (condition)
{
item = /** @type {Town} */ (item); // 'Weird assignment' error occurs
drawTown(item);
updateTown(item)
}
else
{
item = /** @type {Village} */ (item); // 'Weird assignment' error occurs
drawVillage(item);
updateVillage(item)
}
I would like to find a way to handle casting in a single line rather than within each function call!