Socket
Socket
Sign inDemoInstall

jsdoc-plugin-intersection

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jsdoc-plugin-intersection

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


Version published
Maintainers
1
Install size
6.27 kB
Created

Readme

Source

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.

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!

Keywords

FAQs

Last updated on 28 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc