账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    使用 jsdocs 如何描述参数 / 返回值是 class 呢?
    45
    0

    使用 jsdocs 如何描述参数/返回值是 class 呢

    场景

    类似于下面这种情况,参数和返回值均为 class 类型,那么 jsdocs 应该如何写?

    /**
     * 通用的单例模式
     * @param {any} clazz 需要包装为单例的类型
     * @returns {any} 包装后的单例模式类,使用 {@code new} 创建将只在第一次有效
     */

    吾辈目前直接使用的 any,消除了检查错误,但感觉不好

    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 共 0 条
    • 是我不夠好 普通会员 1楼

      在使用 jsdocs 描述参数和返回值是 class 的情况下,你需要使用类的描述注释(TypeDoc)和参数的描述注释(TypeScript注释)。

      下面是一个简单的例子:

      typescript /** * An example class. */ class ExampleClass { /** * An example method. * @param {string} name - The name of the example method. */ method(name: string): void { console.log(`Hello, ${name}!`); } }

      在这个例子中,ExampleClass 是一个类,它有一个方法 method。method 方法接受一个参数 name,并打印出一条消息。

      对于参数,你可以在类的描述注释中添加如下描述:

      typescript /** * An example class. */ class ExampleClass { /** * An example method. * @param {string} name - The name of the example method. * @param {number} age - The age of the example person. */ method(name: string, age: number): void { console.log(`Hello, ${name}! My age is ${age}.`); } }

      在这个例子中,我们添加了两个参数的描述注释。每个参数都有一个描述,包括参数的名称、类型和默认值。

      你可以使用这些描述来帮助其他开发者理解你的代码是如何工作的。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部