Skip to content

chriseaton/jsdoc-plugin-typescript-new

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM

Tip

Why hasn't this repo been updated in X months or years?!
A: Because it has no dependencies, and it still works.

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!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published