[英]What's the best way to document an array of arrays of arrays using JSDoc?
I have the following data structure.我有以下数据结构。 The element types of the root array are fixed.
根数组的元素类型是固定的。 What is the best way to document such a structure using JSDoc?
使用 JSDoc 记录这种结构的最佳方法是什么?
[
[
['aqua-160', 160, 'PreCleaning'],
['aqua-260', 260, 'PreCleaning']
],
[
['aqua-360', 360, 'PostCleaning']
]
];
I would use a @typedef
for this:我会为此使用
@typedef
:
/** @typedef {[string, number, string]} MyTuple */
Which you can apply as follow:您可以申请如下:
/** @type {Array<Array<MyTuple>>} */
const x = [ [ ['aqua-160', 160, 'PreCleaning']
, ['aqua-260', 260, 'PreCleaning']]
, [ ['aqua-360', 360, 'PostCleaning']]];
When you mouse over the x
variable in VS Code here's what you can see:当您将鼠标悬停在 VS Code 中的
x
变量上时,您可以看到以下内容:
With VS Code you can also do some type checking with a // @ts-check
"directive" at the top of the file:使用 VS Code,您还可以使用文件顶部的
// @ts-check
“指令”进行一些类型检查:
// @ts-check
/**
* @typedef {[string, number, string]} MyTuple
*/
/** @param {Array<Array<MyTuple>>} z */
function y(z) {
return 42;
}
y('4');
VS Code is able to see that the z
parameter is wrong: VS Code 能够看到
z
参数是错误的:
See also也可以看看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.