hosseinmd/prettier-plugin-jsdoc

Breaks Google Closure type "optional" return type

turadg opened this issue · 3 comments

TypeScript supports the Google Closure style in JSDoc to indicate a param is optional:

/**
 * @param {string=} p2 - An optional param (Google Closure syntax)
 * @param {string} [p3] - Another optional param (JSDoc syntax).
 */

This formatter converts the former to the latter,

/**
 * @param {string} [p2] - An optional param (Google Closure syntax) <-- NOT ANYMORE
 * @param {string} [p3] - Another optional param (JSDoc syntax).
 */

That's fine because it means the same thing. The problem is it also does this for return types:

/** @returns {string=} */

becomes

/** @returns {string} */

That changes the type of the return from string | undefined to string, a breaking change.

We could fix it, but I think that could be more cool if you change it to /** @returns {string | undefined} */

Maybe this parser should do it too.

Fixed V0.3.32