1
如何在google關閉中註釋JSON響應的界面?如何在google-closure界面中註釋@attributes
我必須使用JSONP接口,它實際上將一些XML轉換爲JSON並將其作爲參數提供給我的回調。但不幸的是,起源XML包含一些屬性,所以我得到一個帶有@ attributes-fields的JSON對象,例如
{
"output": {
"foo": "bar"
},
"@attributes": {
"baz": "attr"
}
}
我創建了一個谷歌屏蔽接口,因此編譯器不會再壓縮意外我的領域,我得到了我的IDE整齊自動complition。
/**
* @interface
*/
var JsonResult = function() {};
/**
* @type {JsonResultOutput}
*/
JsonResult.prototype.output;
/**
* @type {JsonResultAttributes}
*/
JsonResult.prototype['@attributes'];
/**
* @interface
*/
var JsonResultOutput = function() {};
/**
* @type {string}
*/
JsonResultOutput.prototype.foo;
/**
* @interface
*/
var JsonResultAttributes = function() {};
/**
* @type {string}
*/
JsonResultAttributes.prototype.baz;
不幸的是,如果我嘗試註釋括號和字符串中的字段,編譯器會觸發警告。所以我的問題是現在:我應該如何註釋這個去除警告?也許我可以在界面中刪除這個字段,因爲我必須以相同的方式在代碼中編寫這個字段,所以編譯器永遠不會縮小這個字段。但我也想在它的完整結構中記錄對象。
感謝偉大的想法。我通過在加載到更多目標導向格式後立即轉換結果並僅註釋其他字段來做出解決方法。我還爲轉換和界面記錄了問題,並添加了描述性評論,但您的解決方案看起來好多了。不過,我會爲這種行爲寫一張票,以澄清如何正確處理這個問題。 – nemoinho