Skip to content

Support Typescript Assertion Functions #250

@cowwoc

Description

@cowwoc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions