jsdoc-plugin-typescript-new v1.0.0
JSDoc TypeScript New Plugin
Converts TypeScript "new" method types (new()
, new() => X
) to a JSDoc-compatible instanceOf(X)
type.
Specifically, this creates a compatibility between Visual Studio Code's TypeScript documentation and JSDoc, as
Visual Studio Code's parser uses the new()
function type to indicate a new instance of a type, but doesn't understand
JSDoc's instanceOf()
(and vice-versa).
You may find my other JSDoc plugins interesting:
Solving the Problem
Using JSDoc in Visual Studio code with their TypeScript-oriented new typedef:
/**
* This is my favorite constructor-like generic function.
* @template T
* @typedef {new(...args: Array) => T} Constructor
**/
Results in...
ERROR: Unable to parse a tag's type expression for source file ...: Invalid type expression "new(...)": Expected "!", "=", "?", "[]", "|", or end of input but "(" found.
Uh oh! JSDoc doesn't like this. It's a TypeScript thing and isn't meant to be supported by JSDoc!
Resolution
Thankfully, this JSDoc plugin solves the problem by converting your new statements into new JSDoc-compatible function tags.
Just Install
yarn add jsdoc-plugin-typescript-new --dev
or
npm install jsdoc-plugin-typescript-new --save-dev
Update your JSDoc configuration, and include the plugin:
...
"plugins": [
"jsdoc-plugin-typescript-new"
],
...
That's all!
4 years ago