如何在 google-closure 接口中注释@attributes
How to annotate @attributes in google-closure interfaces
如何在 google 闭包中注释 JSON-响应的接口?
我必须使用 JSONP 接口,它实际上将一些 XML 转换为 JSON 并将其作为参数提供给我的回调。但不幸的是,原点 XML 包含一些属性,所以我得到一个带有 @attributes-fields 的 JSON-Object,例如
{
"output": {
"foo": "bar"
},
"@attributes": {
"baz": "attr"
}
}
我创建了一个 google-closure 接口,这样编译器就不会意外地缩小我的字段,并且我在 IDE.
中得到了整洁的自动完成
/**
* @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;
不幸的是,如果我尝试在方括号和字符串中注释字段,编译器会发出警告。所以我现在的问题是:我应该如何对此进行注释以删除警告?也许我可以在界面中删除这个字段,因为我也必须在代码中以相同的方式编写这个字段,所以编译器永远不会缩小这个字段。但我也想记录对象的完整结构。
我觉得这像是一个错误。欢迎在 https://github.com/google/closure-compiler
提交问题
要解决此问题,您必须使用对象文字键:
JsonResult.prototype = {
/**
* @type {JsonResultAttributes}
*/
'@attributes': {}
};
如何在 google 闭包中注释 JSON-响应的接口?
我必须使用 JSONP 接口,它实际上将一些 XML 转换为 JSON 并将其作为参数提供给我的回调。但不幸的是,原点 XML 包含一些属性,所以我得到一个带有 @attributes-fields 的 JSON-Object,例如
{
"output": {
"foo": "bar"
},
"@attributes": {
"baz": "attr"
}
}
我创建了一个 google-closure 接口,这样编译器就不会意外地缩小我的字段,并且我在 IDE.
中得到了整洁的自动完成/**
* @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;
不幸的是,如果我尝试在方括号和字符串中注释字段,编译器会发出警告。所以我现在的问题是:我应该如何对此进行注释以删除警告?也许我可以在界面中删除这个字段,因为我也必须在代码中以相同的方式编写这个字段,所以编译器永远不会缩小这个字段。但我也想记录对象的完整结构。
我觉得这像是一个错误。欢迎在 https://github.com/google/closure-compiler
提交问题要解决此问题,您必须使用对象文字键:
JsonResult.prototype = {
/**
* @type {JsonResultAttributes}
*/
'@attributes': {}
};