gpt4 book ai didi

javascript - 如何在 google-closure 接口(interface)中注释 @attributes

转载 作者:行者123 更新时间:2023-11-28 06:18:41 24 4
gpt4 key购买 nike

如何在 Google 闭包中注释 JSON 响应的接口(interface)?

我必须使用 JSONP 接口(interface),它实际上将一些 XML 转换为 JSON 并将其作为参数提供给我的回调。但不幸的是,原始 XML 包含一些属性,因此我得到一个带有 @attributes-fields 的 JSON 对象,例如

{
"output": {
"foo": "bar"
},
"@attributes": {
"baz": "attr"
}
}

我创建了一个 google-closure 接口(interface),这样编译器就不会意外缩小我的字段,并且我在 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': {}
};

关于javascript - 如何在 google-closure 接口(interface)中注释 @attributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35724828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com