简体   繁体   English

使用 JSDoc 记录 arrays 的 arrays 数组的最佳方法是什么?

[英]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.

相关问题 使用 jsdoc 记录回调的正确方法是什么? - What's the proper way to document callbacks with jsdoc? 每次遇到元素时将数组拆分为多个数组的最佳方法是什么? - What's the best way to split an array into multiple arrays every time an element is met? 使用 ECMASCRIPT 6 生成器/函数求和 arrays 的最佳方法是什么 - What is the best way to sum arrays using ECMASCRIPT 6 Generator/Functions 使用 javascript 组合两个 arrays 的最佳方法是什么? - What is the best way to combine two arrays using javascript? 使用JSDoc记录jQuery参数类型的正确方法是什么? - What's the correct way to document a jQuery parameter type with JSDoc? 在 Javascript 中处理大型 arrays 的最佳方法是什么? - What is the best way to process large arrays in Javascript? 合并嵌套 arrays 的最佳方法是什么 - What is the best way to merge nested arrays 使用 jsdoc 记录匿名对象和函数的最佳方式 - Best way to document anonymous objects and functions with jsdoc AMD + Backbone + JSDoc3文档的最佳方式 - AMD + Backbone + JSDoc3 best way to document 检查 arrays 数组是否包含 JavaScript 中的另一个数组的最佳优化方法是什么? - What is the best optimize way to check if array of arrays contains another array in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM