Skip to content

Converts TypeScript-like intersection types to JSDoc compatible union types, that is, from & -> |

License

Notifications You must be signed in to change notification settings

chriseaton/jsdoc-plugin-intersection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM

JSDoc Intersection Plugin

Converts TypeScript intersection types (joined with an "&") to a JSDoc type union "|" allowing the file to be processed downstream. This allows you to use the amperstand "&" in your code.

Specifically, this creates a compatibility between Visual Studio Code's TypeScript documentation and JSDoc, as Visual Studio Code's parser uses amperstands for type unions, and JSDoc uses pipes.

You may find my other JSDoc plugins interesting:

Solving the Problem

Using JSDoc in Visual Studio code with their TypeScript-oriented intersection:

/**
 * This is my favorite function!
 * @param {SomeClass & {abc: 123}}
 */

Results in...

ERROR: Unable to parse a tag's type expression for source file ...: Invalid type expression "SomeClass & {abc: 123}": Expected "|" but "&" found.

Uh oh! JSDoc doesn't like this. It's a TypeScript thing and won't be supported.

Resolution

Thankfully, this JSDoc plugin solves the problem by converting your intersecting types to compatible JSDoc union types. There's no need to hack your code together with strange @typedefs.

Just Install

yarn add jsdoc-plugin-intersection --dev

or

npm install jsdoc-plugin-intersection --save-dev

Update your JSDoc configuration, and include the plugin:

...
    "plugins": [
        "jsdoc-plugin-intersection"
    ],
...

That's all!

About

Converts TypeScript-like intersection types to JSDoc compatible union types, that is, from & -> |

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published