otris / jsdoc-tsd

JSDoc template for generating TypeScript definition files based on JSDoc comments.
MIT License
29 stars 7 forks source link

Support callback-Type #28

Closed wehrstedt closed 6 years ago

wehrstedt commented 6 years ago

For JS-Callbacks you have the possibility to describe a callback function with the @callback-annotation. The module generates currently an empty interface for that

Example:

/**
  * Description of my callback
  * @memberof myNamespace
  * @callback myCallback
  * @param {string} param1 Description of param1
  * @returns {string} Description of the return value
  */

/**
  * Description of my function
  * @memberof myNamespace
  * @param {myNamespace.myCallback} callback My callback param
  */
function test(callback) {
    // ...
}

Generated output:

declare namespace myNamespace {
    interface myCallback {
    }

    function test(callback: myCallback): void;
}

Expected output:

declare namespace myNamespace {
    declare type myCallback = (param1: string) => string;

    function test(callback: myCallback): void;
}
wehrstedt commented 6 years ago

implemented with e4fcd8bd70b24fb1758a37495dcdafb594e5b191