JSDoc是一种用于向JavaScript源代码添加内联API文档的语法。这与解析和操作遵循JSDoc语法的代码的各种工具不同。
JSDoc - 如何在 Eclipse 中检查 JavaScript 类型?
我正在应用 JSDoc 注释: /** * @param {number} 毫秒 * @param {function} 回调 * */ 函数睡眠(毫秒,回调){ 设置超时(函数(){ 打回来(); },毫利斯)...
我正在寻找类似 ESLint 的东西,但它实际上会根据 JSDoc @param 标签验证类型。我尝试了 ts-node 但它似乎没有强制执行。例如,这不会抛出: /** * 一个...
在 javascript 中,使用 JSDoc,我正在查询页面上的元素: // @ts-检查 /** @type {HTMLInputElement} */ const element = document.getElementById('checkbox'); 但我收到警告: 输入“
如何使用 jsdoc 记录一组从另一个函数的返回值解构而来的函数?
首先,我已经阅读了这个问题/答案,它不太适合我的情况。 我正在调用一个库函数,它动态创建并返回一个函数数组。然后我的模块...
我有一个名为namespace.event 的事件。当我想使用标签 @fires 时,这些点会在 JsDoc 中引起问题。当我做: /** @fires MyClass#namespace.myevent */ 我得到的结果是纯文本M...
VScode 中带有上次修改时间的自动 JSDoc 风格注释
在 Sublime text 中,有一些选项或插件允许您将其放在文件顶部: /** *@最后修改时间: */ 每当您保存时,它都会添加实际时间
我知道可以将整个属性注释为已弃用,但是是否可以将字符串联合中的一个(或多个)单个值注释为已弃用? 例如,给定这个类型声明...
我一直在尝试使用 JSDoc 来记录 JS 中的重载函数: 有 2 个用例: 分配Slave(票证,用户ID); allocateSlave(票,名字,姓氏); 我想让它看起来像这样
我在 JavaScript 中有以下两行: /** @类型 {*} */ const Slides = document.getElementsByClassName("x"); 我正在使用 JSDoc 来记录这一行。 “*”需要重新填写...
我正在使用 JSDoc 并对 Stream 有以下定义: /** * @模板T * @callback流 * * @param {T} [值] * * @return {T} 值 */ 这正确地翻译为...
如何使用 VS Code 将 typedef 从一个文件“导入”到 JSDoc 中的另一个文件?
假设我有一个名为“File1.js”的文件。在这个文件中,我导出一个对象的对象,并为每个对象提供一个 typedef,如下所示。 /** * 我为每个对象定义的类型。 * @typedef {Object} MyObject1 *@
当函数使用与预期不同数量的参数时,为什么 TypeScript 不发出警告?
我在 VS Code 中有一个普通的 JavaScript 项目,设置了 jsconfig.json 和以下示例代码: /** * @param {(arg: string) => void} 嵌套函数 */ 函数 myFunction(nestedFuncti...
我花了相当长的时间在互联网上搜索,寻找使用 jsdoc 正确记录回调的最佳方法,但不幸的是,我还没有找到一个很好的方法。 这是我的问题: 我已书面...
收到 TS 2352 错误: 将类型“X”转换为类型“Y”可能是错误的,因为两种类型都没有与另一种类型充分重叠。如果这是故意的,请将表达式转换为“未知”
我正在寻找 tsc 中此错误的解决方法:https://github.com/microsoft/TypeScript/issues/50436 问题一: 包范围的类型在包外部不可用。 如果你声明一个类型...
我有以下代码片段文件,我想在其中添加 JSDoc 以便在代码的 {each} 部分中定义表格和表格。 从“../store/dialog.s...</desc>导入{对话框}” <question vote="0"> <p>我有以下代码片段文件,我想在其中添加 <strong>JSDoc</strong> 以便定义代码的 <pre><code>tables and table in {each}</code></pre> 部分。</p> <pre><code><script> import { dialog } from "../store/dialog.svelte"; /** * The tables to be displayed. */ let { tables } = $props(); /** * Logs the ID of a table for an order. * * @function * @param {Object} table - The table object containing information about the order. * @param {number} table.id - The unique identifier for the table. * @param {string} table.name - The name of the table. * @returns {void} */ function getOrder(table){ dialog.open = true; dialog.title = `${table.name} Order`; } </script> {#each tables as table} <div class="card bg-base-100 shadow-xl"> <div class="card-body py-2 px-1"> <h2 class="card-title">{table.name} <sup class="text-sm">({table.seats}<i class="fa-solid fa-chair"></i>)</sup> {#if table.order } <sup> <button class="bg-green-500 text-white p-2 rounded-full transition duration-300 ease-in-out transform hover:scale-105 animate-pulse" ></button> </sup> {/if} </h2> <div class="card-actions justify-end"> <button class="btn btn-info btn-xs" onclick="{() => getOrder(table)}">Show Order</button> </div> </div> </div> {/each} </code></pre> <p>这是传递<strong>props</strong>的地方:</p> <pre><code><script> import { tables } from "../store/tables.svelte"; import Table from "../snippets/Table.svelte"; </script> <nav id="mainNav"> <h3>Tables</h3> <div class="divider"></div> <div class="border grid grid-cols-4 gap-4 justify-between py-5 px-2 bg-gray-100"> <Table tables={tables.tables}></Table> </div> </nav> </code></pre> <p>这是<strong>桌子</strong>的商店:</p> <pre><code>import { user } from "./user.svelte" function createTables(){ /** * @typedef {Object} Waiter * @property {number} id */ /** * @typedef {Object} table * @property {number} id * @property {string} name * @property {number|null} seats * @property {null|Object} order * @property {Waiter} waiter */ /** * @type {Array.<table>} tables */ let tables = $state([]) let userTables = $derived(() => { return tables.filter(table => { return +user.currentUser?.id === +table.waiter?.id }) }) let userTablesFree = $derived(() => { return tables.filter(table => { return +user.currentUser?.id === +table.waiter?.id && table.order === null }) }) let userTablesUsed = $derived(() => { return tables.filter(table => { return +user.currentUser?.id === +table.waiter?.id && table.order !== null }) }) let otherTablesFree = $derived(() => { return tables.filter(table => { return +user.currentUser?.id !== +table.waiter?.id && table.order === null }) }) let otherTablesUsed = $derived(() => { return tables.filter(table => { return +user.currentUser?.id !== +table.waiter?.id && table.order !== null }) }) return { get tables(){ return tables }, set tables(newValue){ tables = newValue }, userTables, userTablesFree, userTablesUsed, otherTablesFree, otherTablesUsed } } export const tables = createTables() </code></pre> </question> <answer tick="false" vote="0"> <p>您应该能够使用 <pre><code>@typedef</code></pre> 和 <pre><code>@type</code></pre>,例如 </p> <pre><code>/** * @typedef {Object} Props * @property {number} number A number prop. * @property {string} text A string prop. */ /** @type {Props} */ const { number, text } = $props(); </code></pre> <p>如果您不在单独的 <pre><code>.d.ts</code></pre> 文件中声明类型(我建议对于更复杂的类型),则可以在类型中使用 <pre><code>import</code></pre> 语句。例如</p> <pre><code>/** * @typedef {Object} Props * @property {typeof import('./tables.svelte.js').tables} tables Tables */ </code></pre> <p>另外:我<strong>不</strong>建议使用全局状态(<pre><code>export const tables = ...</code></pre>),特别是如果你有SSR,那么这是一个隐私/安全风险。</p> </answer> </body></html>
想象一个接受“onUpdate”函数作为参数的函数: /** * @param {函数} onUpdate * @返回{null} */ 静态异步初始化(onUpdate){ ... onUpdate(true);...
假设下面是一个泛型类型,我应该用什么来代替 ???正确记录T? /** * ??? T 的描述。 */ 类我的类 { } 在 C# 中我会使用 。有没有
我正在尝试使用 JSDocs 来获取 isEqual(object1: T, object2: T) 但我收到警告:类型“T”未定义 .eslintjsdoc/no-undefined-types。 我该如何修复这里的 eslint 警告? /*...
我正在尝试使用 JSDoc 来记录我的反应状态挂钩的解构部分,例如: const [referenceState, setReferenceState] = useState(null); 这里,referenceState是Object类型,...