JSDoc是一种用于向JavaScript源代码添加内联API文档的语法。这与解析和操作遵循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类型,...
如何从 JavaScript+JSDoc 中的模块导入类型定义?
我正在尝试将类型定义从 JSDoc 中的模块导入到我的 SvelteKit 应用程序中。 这是我尝试以 JS/JSDoc 形式实现的 TypeScript 代码: 从 '@
例如,Discord 和 Messenger 中社区聊天的分类法不同,但它们提供相同的功能: 不和谐 信使 服务器 社区 文字频道/论坛频道 交流...
我正在尝试记录以下 Person 构造函数的 getName() 方法: JavaScript 代码: /** * 创建一个人实例。 * @param {string} name 该人的全名。 * @构造...
我有一个由 user.model.js 中的某个函数返回的用户对象 常量用户 = { id: "ASwsd122Wqwe1", 姓名:“萨姆”, 电子邮件:“[email protected]”, 创建日期:
我有一个接受对象数组的函数。 看起来像这样。 myAwesomeFunction([ { 名称:'某个名称', 下一个:假, 测试一下' }, { 名称:'名称...
我有一个 JavaScript 函数获取一些参数,包括对象类型。但是,参数的一个属性(即对象)将被弃用。我想指出这个情况...
给出这段代码: 函数 asyncFoo() { 返回新的 Promise(函数(履行,拒绝){ doAsyncStuff(函数(错误,数据){ 如果(错误)拒绝(新错误(错误)); 否则满足(新酒吧(d...
为什么我的函数的参数显示为布尔值(使用 JSDocs),而事实并非如此?
我记录了我对 React 井字棋教程的复制,我不明白为什么我的函数的参数显示为布尔值(使用 JSDocs),而事实并非如此。 这就是
我是 JSDocs 的新手,找不到这个问题的答案。 假设我想写这个简单的函数: 函数 hasQ(array, item) {return array.includes(item);} 与 JSDoc'...