better-docs
better-docs copied to clipboard
Support Typescript Assertion Functions
Per https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions the following Typescript code is valid:
/**
* Throws an <code>Error</code> if <code>condition</code> is false.
*
* @param {boolean} condition a condition
* @param {Error} [error = Error] the type of error to throw
* @param {string} message the error message to use on failure
* @throws {Error} if <code>condition</code> is false
*/
static assert(condition: boolean, error: (message?: string) => Error = Error, message?: string):
asserts condition
{
// Will be stripped out using uglify.js option "pure_funcs"
if (!condition)
throw error(message);
}
However, when I run jsdoc against using better-docs/typescript
plugin I get:
ERROR: Unable to parse a tag's type expression for source file C:\Users\Gili\Documents\requirements.js\target\jsdoc-workaround\internal\Objects.ts in line 429 with tag title "return" and text "{asserts condition}": Invalid type expression "asserts condition": Expected "|" but "c" found.
As a workaround, I now replace all instances of "asserts condition" with "void" before running jsdoc. This made the error disappear.