Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Typescript Assertion Functions #250

Open
cowwoc opened this issue Jul 4, 2023 · 0 comments
Open

Support Typescript Assertion Functions #250

cowwoc opened this issue Jul 4, 2023 · 0 comments

Comments

@cowwoc
Copy link

cowwoc commented Jul 4, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant