本文介绍了如何使用jsdoc记录解构变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的东西:
let { total } = settings;
如何记录总变量?我尝试过这样的事情:
How do I document the total variable? I tried something like this:
/**
* @type {Object}
* @property {String} total.test
*/
let { total } = settings;
但这似乎不是正确的方法.
but it doesn't seem to be the right way.
有什么建议吗?
推荐答案
@ Tommy-Pepsi Gaudreau 他对原始问题的评论是如此贴切.
@Tommy-Pepsi Gaudreau was so close in his comment on the original question.
这是一个关闭编译器工具中的示例@ closure-compiler.appspot.com
let /** @type {Object<string|boolean>} */ settings = {};
let str = 'string';
let bool = true;
settings.b = bool;
settings.s = str;
// Note that at this point, b and s are of the type {string|boolean}.
let {/** @type {string} */ s,/** @type {boolean} */ b } = settings;
console.log({b, s});
// But now, when we assign the wrong types, we get a warning.
b='warn';
s=false;
警告数量:2
JSC_TYPE_MISMATCH: assignment
found : string
required: boolean at line 15 character 4
b='warn';
^
JSC_TYPE_MISMATCH: assignment
found : boolean
required: string at line 16 character 4
s=false;
^
Edit-2018年9月27日:我减少了初始键入的数量,以确保/澄清类型不会被忽略,并且警告来自破坏结构中的类型.
Edit - Sep 27, 2018: I've reduced the amount of initial typing to ensure/clarify the types weren't being ignored, and that the warnings were coming from the types in the destructuring.
这篇关于如何使用jsdoc记录解构变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!