otris / jsdoc-tsd

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

Typedefinition in function paramaters with different types #70

Open wehrstedt opened 5 years ago

wehrstedt commented 5 years ago

You can do something like this:

/**
 * @typedef {string} SomeType
 */

/**
 * @param {SomeType|object} fuu Some string identifier or an object
 * @param {string} fuu.bar Some property of object fuu
 */
function fuuBar(fuu) {
}
*/

This will fail because the plugin tries to create a type alias definition but will reject because properties are defined. The code above should instead create a type definition for the passed object. Both types should be keep in the parameter type.

wehrstedt commented 5 years ago

As a workaround you can switch the order of the types. Instead of string|object you can pass object|string.

Maybe the plugin should be "smarter". If properties are passed and of least one of the passed types is of type object, everything is fine. But now it just takes the first type.