【问题标题】:Adding Description to typescript .d.ts files向 typescript .d.ts 文件添加描述
【发布时间】:2021-10-19 20:42:36
【问题描述】:

我们正在尝试编写一个 js 库,并且我们使用 .d.ts 文件来帮助处理发射和其他东西。 但是我们想不通的是如何向它添加描述。 我们现在拥有的:

我们想要什么:

【问题讨论】:

    标签: javascript typescript npm


    【解决方案1】:

    使用JSDoc syntax,像这样:

    /**
     * Does something.
     */
    declare function foo(name: string, age: number): string;
    

    【讨论】:

      【解决方案2】:

      听起来你应该使用TSDoc

      这里是一个例子,但你显然应该比这个例子更努力地描述你的描述:

      /**
       * Log into the system.
       * 
       * @param config - The config object
       * @param userLogin - The user name to login with
       * @param userPassword - The password to login with
       * @param recaptchaResponse - The recaptcha response
       */
      function login(config: any, userLogin: any, userPassword: any, recaptchaResponse: any): Promise<any>
      {
          ////
      }
      

      利用 TypeScript 的类型系统也很有帮助。尽可能不要使用any。你应该提供实际的类型,然后你会得到更好的文档。

      如果这只是提供“any”的原因,您还可以提供多个类型,使用这样的联合类型:

      (myParam: number | string)
      

      【讨论】:

        猜你喜欢
        • 2020-04-19
        • 2021-05-02
        • 2012-01-31
        • 2016-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-04-14
        相关资源
        最近更新 更多